Formatting Numbers by Locale ( Intl.NumberFormat Javascript)

Formatting number is a very common feature request in web applications as it makes reading large numbers a bit easier. What makes it tricky is non-standard formats across the world. For example, many European countries such as Germany, Italy, France do not essentially use commas as a separator and use spaces or periods instead and to add to that some European countries use comma as a decimal separator (see table below).
For example, the number 123456789.321 is formatted as below for these countries:

Country Formatted Description
1 USA 123,456,789.321 `,` as a separator and `.` as decimal
2 France 123 456 789,321 `space` as a separator and `.` as decimal
3 Italy 123.456.789,321 `.` as a separator and `,` as decimal
4 Liechtenstein 123’456’789.321 `'` as a separator and `.` as decimal
5 India 12,34,56,789.321 `'` as a separator and `.` as decimal

USA and a majority of countries follow the pattern where comma (or space or period) is placed every three decimal places to the left of the decimal point.
However for India, this pattern is different and while the first comma is placed three decimal places to the left of the decimal point, the rest are placed every two digit there on. So in short, the format is not unique across regions (see table above).

Fortunately, in javascript (ECMAScript) Intl object is Internationalization API that provides number formatting amongst other things out of the box. So there’s no need of writing any functions or using external libraries.


new Intl.NumberFormat([locales[, options]])

Here locale is the language subtag. (ISO Codes for language)
Example – en-us for English (United States) , fr for French (Standard), it for Italian (Standard), hi for Hindi (India) so on.

Intl.NumberFormat('en-us').format(123456789.321) // will return
Intl.NumberFormat('hi').format(123456789.321) // will return

The language code can also be fetched from Browser’s native navigator object

So the following js code will give you the number format as per the users browser language setting

const getFormattedNumber = (inputNumber) => {
const languageCode = navigator.language
const formattedNumber = new Intl.NumberFormat(languageCode).format(inputNumber)
console.log({languageCode, formattedNumber}) // can be replaced with a return

There’s a lot more that can be done with options for example :

// Intl.NumberFormat(locale, options).format(number)
// Here options is set to {style: 'currency', currency: 'USD'}
new Intl.NumberFormat('en-US', {style: 'currency', currency: 'USD'}).format(123456789.99);
new Intl.NumberFormat('hi', {style: 'currency', currency: 'INR'}).format(123456789.99);
new Intl.NumberFormat('en-US', {style: 'currency', currency: 'GBP'}).format(123456789.99);
new Intl.NumberFormat('en-GB', {style: 'currency', currency: 'GBP', notation: "compact"}).format(123456789.99);
new Intl.NumberFormat('en-US', {notation: "compact",compactDisplay: "long"}).format(123456789.99);
"123 million"
new Intl.NumberFormat('hi', {notation: "compact",compactDisplay: "long"}).format(123456789.99);
"12 करोड़" // 12 Crore

And some more

Intl.NumberFormat('hi', {numberingSystem:'deva'}).format(123456789.321)
"१२,३४,५६,७८९.३२१" //Devanagri

Intl.NumberFormat('en-US', {numberingSystem:'beng'}).format(123456789.321)
"১২,৩৪,৫৬,৭৮৯.৩২১" // Bengali

Intl.NumberFormat('en-US', {numberingSystem:'orya'}).format(123456789.321)
"୧୨୩,୪୫୬,୭୮୯.୩୨୧" // Oriya

Intl.NumberFormat('hi', {numberingSystem:'telu'}).format(123456789.321)
"౧౨,౩౪,౫౬,౭౮౯.౩౨౧" // Telugu

Intl.NumberFormat('hi', {numberingSystem:'mlym'}).format(123456789.321)
"൧൨,൩൪,൫൬,൭൮൯.൩൨൧" // Malayalam

Intl.NumberFormat('en-US', {numberingSystem:'mong'}).format(123456789.321)
"᠑᠒᠓,᠔᠕᠖,᠗᠘᠙.᠓᠒᠑" // Mongolian

Intl.NumberFormat('en-US', {numberingSystem:'thai'}).format(123456789.321)
"๑๒๓,๔๕๖,๗๘๙.๓๒๑" // Thai

Intl.NumberFormat is supported by almost all leading browsers
Can I use Intl.NumberFormat ?

Posted in Generic, Javascript, Web Technology

Implementing KMeans Clustering in Python

Created By: Debasis Das(23-Feb-2021)

In this post we will see how KMeans clustering works by using sklearn KMeans Cluster and by manually writing the KMeans Clustering logic and comparing the results.

The manual approach code is a sample to demonstrate the iterative process of starting with random centroids and updating the cluster labels for each point based on its proximity to the centroids and then updating the centroids as the mean of all the points in the cluster for the given centroid and repeat the process (update cluster label, update centroids) for a given number of iterations

KMeans is a very simple algorithm to implement, has a downside of being very sensitive to noise. KMeans will try to assign a cluster to noise points as well. There are known challenges such as identifying the initial cluster centroids and initial cluster centroid selection has an effect on how the clusters will be formed.

Posted in Data Mining, Data Science, Python Tagged with: , ,

Pandas DataFrame – Pivot, Groupby, Filter, Query

Created By: Debasis Das (18-Feb-2021)

In this post we will explore the following DataFrame functions

  • pivot_table
  • groupby
  • filter
  • query
import pandas as pd
import numpy as np

df = pd.read_csv("SalesData.csv",low_memory=False)

The working DataFrame is as below and we will use different DataFrame functions to slice and dice the data.

Pivoted view of the above Data 

df1 = pd.pivot_table(df,index=["Region","Country","Product"],aggfunc=np.sum)

Pivot using only 2 columns, the data corresponding to the Products will be rolled up.

df2 = pd.pivot_table(df,index=["Region","Country"],aggfunc=np.sum)


Multi-Level Column Pivot 

DataFrame pivot with multi level in columns (Week followed by product)

df3 = pd.pivot_table(df,index=["Region","Country"],columns=["Product"],aggfunc=np.sum)

df4 = pd.pivot_table(df,index=["Region","Country"],columns=["Product"],values = ["WK_1","WK_2"],aggfunc=np.sum)


Adding a new column to the pivot table 

df5 = pd.pivot_table(df,index=["Region","Country"], aggfunc=np.sum)
df5['Total'] = df5['WK_1'] + df5['WK_2']+ df5['WK_3'] + df5['WK_4']


DataFrame Filter

fdf1 = df[df["Region"] == "America"]

Using the DataFrame Filter function

fdf3 = df.filter(["Region", "Country", "WK_1"]) 

DataFrame groupby function

gdf1 = df.groupby(['Region']).sum()

gdf3 = df.groupby(['Region',"Country","Product"],sort=True).sum()

groupby and get_group

gdf4 = df.groupby(["Country","Product"]).get_group(('Canada','Laptop'))

gdf5 = df.groupby(["Region","Product"]).get_group(('America','Phone'))

Iterating through a grouped data frame

gdf6 = df.groupby('Country')
for name,group in gdf6:

Using Numpy functions for groupby aggregates

gdf7 = df.groupby(['Region','Product']).aggregate(np.sum)

Using Multiple Aggregate functions in DataFrame groupby

gdf8 = df.groupby(['Region','Country']).aggregate([np.sum,np.mean])

Using a different aggregate function for columns and renaming the column to reflect the function used

gdf10 = df.groupby(['Region']).agg({'WK_1': np.sum, 'WK_2':np.mean}).rename(columns = {'WK_2':'WK_2 (Mean)'})

DataFrame Query

Query to see if one column value is greater than another column

qdf1 = df[df.WK_2 > df.WK_1]

In the below sample week 2 values are greater than week 1 values

qdf2 = df[df.WK_1 > 1500]

Multi Column Query

qdf3 = df[(df.WK_1 > 1500) & (df.WK_2 > 1900)]

Using the DataFrame.query function

qdf4 = df.query('WK_1 > 1500 & WK_2 > 1900')

Posted in Data Mining, Python Tagged with: , , ,

Pandas DataFrame – Different ways to Create and Edit

By Debasis Das (17-Feb-2021)

In this post we will see Different ways of creating a pandas DataFrame and editing it

Lets first import the Python Pandas and numpy module

import pandas as pd
import numpy as np
import random
pd.set_option('display.width', 1000)

Creating a dataframe by reading from a CSV

salesDataDf = pd.read_csv("SalesData.csv",low_memory=False)


    Region  Country Product  WK_1  WK_2  WK_3  Wk_4
0  America      USA  Laptop  1241  1160  1929  1174
1  America      USA   Phone  1098  1092  1089  1819
2  America   Canada  Laptop  1441  1099  1950  1394
3  America   Canada   Phone  1990  1057  1656  1060
4   Europe  Belgium  Laptop  1084  1116  1002  1566
5   Europe  Belgium   Phone  1574  1958  1793  1213
6   Europe  Finland  Laptop  1325  1374  1300  1579
7   Europe  Finland   Phone  1347  1736  1782  1921

Create a DataFrame from a List

seasons = ['Winter','Spring','Summer','Fall']
df = pd.DataFrame(seasons)


0  Winter
1  Spring
2  Summer
3    Fall

Creating a DataFrame from an Array of Array:

data = [[100,200,300],[400,500,600],['John','Jane','Mary','Jin']]
df = pd.DataFrame(data)


  0 1 2 3
0 100 200 300 None
1 400 500 600 None
2 John Jane Mary Jin

Creating a DataFrame by passing an arrays of values and an array of column header names:

df = pd.DataFrame([['Debasis Das',100],['John Doe',98],['Jane Doe',93]], columns = ["name","score"],dtype = float)


  name score
0 Debasis Das 100.0
1 John Doe 98.0
2 Jane Doe 93.0

Create a DataFrame from a Dictionary:

dictionary = {"names":["John Doe","Jane Doe","Mary Jane"], "score":[90,91,93]}
df = pd.DataFrame(dictionary)


  names score
0 John Doe 90
1 Jane Doe 91
2 Mary Jane 93

Create a DataFrame from a List of Dictionaries:

listOfDict = [{"names":"John Doe", "age":30},{"names":"Jane Doe", "age":10, "score":98.0}]
df = pd.DataFrame(listOfDict)


  names age score
0 John Doe 30 NaN
1 Jane Doe 10 98.0

Add a column to the DataFrame based on a condition:

df = pd.DataFrame({'Score':[100,20,30,80,90]})
df.loc[df.Score <= 80, "Grade"] = "B"
df.loc[df.Score > 80, "Grade"] = "A"
df.loc[df.Score < 35, "Grade"] = "F"


0 100
1 20
2 30
3 80
4 90

After adding a new column

 Score Grade
0 100 A
1 20 F
2 30 F
3 80 B
4 90 A

Creating a DataFrame from a numpy array:

df = pd.DataFrame(np.random.randint(low=80, high=100, size=(3, 5)), columns=['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'],index=['Temp Morning', 'Temp Afternoon', 'Temp Evening'])


             Monday Tuesday Wednesday Thursday Friday
Temp Morning   98     88      91         87     91
Temp Afternoon 92     83      80         83     81
Temp Evening   84     94      92         96     84   

Creating a DataFrame with Random Values in few columns

salesData = {"Region":["Americas","Americas","Americas","Americas","Europe","Europe","Europe","Europe"],
salesDF = pd.DataFrame(salesData)


Adding New Columns to an Existing DataFrame:

salesDF["Total"] = salesDF['wk1'] + salesDF['wk2'] + salesDF['wk3'] + salesDF['wk4']
salesDF["Total (K)"] = salesDF["Total"] /1000

Output: In this sample we added 2 new columns (Total and Total In K Format)

Creating a DataFrame using Assign Function

# Assign returns a copy of the data frame as a new object with the new columns added to the original data frame.
salesDF1 = salesDF[["Region","Country","Product","wk1"]]
salesDF2 = salesDF1.assign(week1_k=lambda x: salesDF1['wk1']/1000)


Transpose a DataFrame:

data = {'Col1': [1, 2, 3], 'Col2': [4, 5, 6], 'Col3': [7, 8, 9]}
df = pd.DataFrame(data, index=['Row1', 'Row2', 'Row3'])
df_transpose = df.T

print("\nBefore Transpose")

print("\nAfter Transpose")

Selecting a Subset of a DataFrame using loc

data = {'Col1': [1, 2, 3], 'Col2': [4, 5, 6], 'Col3': [7, 8, 9]}
df = pd.DataFrame(data, index=['Row1', 'Row2', 'Row3'])
df1 = df.loc['Row1':'Row2','Col1':'Col2']
print("\nSubset of the Dataframe")

Merge Dataframes

data1 = {"Country":["USA","Mexico","Brazil"],"Jan_Sales":[1000,2000,3000]}
data2 = {"Country":["Canada","Mexico","Brazil","Belgium"],"Feb_Sales":[4000,5000,6000,7000]}
df1 = pd.DataFrame(data1)
df2 = pd.DataFrame(data2)
#Pandas merge function can automatically detect which columns are common between the dataframes 
#Pandas will use the common columns to merge the two dataframes
Country	Jan_Sales
0	USA	1000
1	Mexico	2000
2	Brazil	3000

Country	Feb_Sales
0	Canada	4000
1	Mexico	5000
2	Brazil	6000
3	Belgium	7000
df3 = df1.merge(df2)
Country	Jan_Sales	Feb_Sales
0	Mexico	2000	5000
1	Brazil	3000	6000

Inner Merge

df4 = df1.merge(df2,how='inner')
Country	Jan_Sales	Feb_Sales
0	Mexico	2000	5000
1	Brazil	3000	6000

Outer Merge

df5 = df1.merge(df2,how='outer')
  Country	Jan_Sales	Feb_Sales
0	USA	1000.0	NaN
1	Mexico	2000.0	5000.0
2	Brazil	3000.0	6000.0
3	Canada	NaN	4000.0
4	Belgium	NaN	7000.0

Left Merge

df6 = df1.merge(df2,how='left')
  Country	Jan_Sales	Feb_Sales
0	USA	1000	NaN
1	Mexico	2000	5000.0
2	Brazil	3000	6000.0

Right Merge

df7 = df1.merge(df2,how='right')
Country	Jan_Sales	Feb_Sales
0	Canada	NaN	4000
1	Mexico	2000.0	5000
2	Brazil	3000.0	6000
3	Belgium	NaN	7000


Posted in Data Mining, Data Science, Python Tagged with: , ,

KMeans Clustering

By: Debasis Das (17-Feb-2021)

KMeans Clustering using SKLearn
Plotting the cluster centroid with the cluster points

import pandas as pd
import numpy as np
from sklearn.cluster import KMeans
from sklearn.decomposition import PCA
import matplotlib.pyplot as plt

A = [

df = pd.DataFrame(A)
number_clusters = 3
pca = PCA(n_components=2)
x_pca = pca.fit_transform(df)
km = KMeans(
    n_clusters=number_clusters, init='random',
    n_init=10, max_iter=300, 
    tol=1e-04, random_state=0

kmeans_labels = km.labels_
unique_labels = np.unique(kmeans_labels)
for i in unique_labels:
        x_pca[kmeans_labels == i, 0], x_pca[kmeans_labels == i, 1]
cluster_centroids = km.cluster_centers_
print("cluster_centroids = ",cluster_centroids)
print("kmeans_labels = ",kmeans_labels)
plt.scatter(cluster_centroids[:,0], cluster_centroids[:,1],linewidths = 3, s=150,marker="x", color='r')


cluster_centroids =  [[ 6.38423083 -1.0142913 ]
 [ 1.67176795  0.63576739]
 [-5.28182536 -0.28756359]]
kmeans_labels =  [2 2 2 2 1 1 1 0 1 0 1]


If you are interested to see how the KMeans clustering can be implemented in Python you can check the below link

Posted in Data Mining, Data Science Tagged with: ,

SSE Calculation for a Clustering

By Debasis Das: (17-Feb-2021)

How to manually calculate the SSE for a Clustering.

Clustering such as KMeans has a inertia_ function that gives the total SSE for the clustering, however clustering such as DBScan lacks an inertia_ function and in this sample code we are going to see how we can derive the SSE number for a clustering

import pandas as pd
from sklearn.cluster import KMeans
from sklearn.decomposition import PCA

A = [[10,10],

df = pd.DataFrame(A)
number_clusters = 2
pca = PCA(n_components=2)
x_pca = pca.fit_transform(df)
km = KMeans(
    n_clusters=number_clusters, init='random',
    n_init=10, max_iter=300, 
    tol=1e-04, random_state=0

kmeans_labels = km.labels_
print("The KMeans Labels are = ",kmeans_labels)
print("The Kmeans SSE using inertia_ function =", km.inertia_)

manual_SSE = 0
for i in range(number_clusters):
    cluster = x_pca[km.labels_ == i]
    if len(cluster) > 0:
            clusterMean = cluster.mean(axis = 0)
            manual_SSE += ((cluster - clusterMean) ** 2).sum()

print("The KMeans SSE using manual calculation = ",manual_SSE)  

# Clustering such as DBScan doesnot have a inertia function 
# and in case one needs to calculate the SSE for a DBScan clustering, 
# we can use the manual method of SSE Calculation

Output: for the given dataset

The KMeans Labels are =  [0 0 0 1 1 1 1]
The Kmeans SSE using inertia_ function = 19.04166666666666
The KMeans SSE using manual calculation =  19.041666666666664

As you can see the SSE calculated matches the SSE given by the inertia_ function.

You can use the same manual approach of using the DBScan Cluster and DBScan Labels to come up with the SSE for DBScan Clustering

Posted in Data Mining, Data Science Tagged with: , , ,

DBScan Clustering Sample

Written By: Debasis Das 

In this post we will generate a DBScan cluster using SKLearn DBSCAN module and will generate the following

  1. List of noise/outlier points (not readily available in DBSCAN model output)
  2. Index of noise/outlier points
  3. View the clusters by cluster label and identify all the core points in the clusters
  4. All the core points, count of core point, indexes of the core points
  5. Estimated number of clusters
  6. Silhouette Score of the Clustering
  7. Silhouette Score of the Clustering by ignoring the noise points

Note: the noise points are those with label -1

import numpy as np
from sklearn.cluster import DBSCAN
from sklearn.metrics import silhouette_samples, silhouette_score
import matplotlib.pyplot as plt

epsilon = 3
min_samples = 2

X = [

# plot
A = np.array(X)
   A[:, 0], A[:, 1],
   c='white', marker='o',
   edgecolor='red', s=50
print("The points prior to running DBScan Clustering")

db = DBSCAN(eps=epsilon, min_samples=min_samples).fit(X)

core_samples_mask = np.zeros_like(db.labels_, dtype=bool)
core_samples_mask[db.core_sample_indices_] = True
labels = db.labels_
no_clusters = len(np.unique(labels) )
no_noise = np.sum(np.array(labels) == -1, axis=0)

noise_index = []
for i in range(len(labels)):
    if labels[i] == -1:
print("Noise/Outliers Index are at the following indexes ",noise_index)
for obj in noise_index:
    print("Noise/outlier point = ",X[obj])

unique_labels = set(labels)
print("unique labels are ",unique_labels)
for label in unique_labels:
    print("cluster points for ", label)
    cluster_indexes = []
    for i in range(len(labels)):
        if labels[i] == label:
    print("cluster_indexes = ",cluster_indexes)        
    for obj in cluster_indexes:
        print("exact point = ",X[obj])

silhouette_avg = silhouette_score(X, labels)

print("Labels ",labels)
print("Indices of Core Samples = ",db.core_sample_indices_)
print("Copy of each core sample found by training = ",db.components_)
print("Count of Core Samples ",len(db.core_sample_indices_))
print('Estimated no. of clusters: %d' % no_clusters)
print('Estimated no. of noise points: %d' % no_noise)
print("silhouette_avg = ",silhouette_avg)
print("Silhoutter Avg ignoring noise points ",(silhouette_avg * len(labels))/(len(labels)-no_noise) )

The points prior to running DBScan Clustering

Noise/Outliers Index are at the following indexes  [5]
Noise/outlier point =  [25, 80]
unique labels are  {0, 1, -1}
cluster points for  0
cluster_indexes =  [0, 1, 2]
exact point =  [1, 2]
exact point =  [2, 2]
exact point =  [2, 3]
cluster points for  1
cluster_indexes =  [3, 4]
exact point =  [8, 7]
exact point =  [8, 8]
cluster points for  -1
cluster_indexes =  [5]
exact point =  [25, 80]
Labels  [ 0  0  0  1  1 -1]
Indices of Core Samples =  [0 1 2 3 4]
Copy of each core sample found by training =  [[1 2]
 [2 2]
 [2 3]
 [8 7]
 [8 8]]
Count of Core Samples  5
Estimated no. of clusters: 3
Estimated no. of noise points: 1
silhouette_avg =  0.7227526416896678
Silhoutter Avg ignoring noise points  0.8673031700276013

Further Read/ References

Posted in Data Mining, Data Science Tagged with: , , ,

eCharts (v3) Gauge chart

eCharts (v3) has captured my attention and am impressed. Lets create a gauge chart and also understand the code.

Note: CDN for english version of echarts version 3 can be found here :


<!doctype html>
<title>Charts Gauge Example</title>
<div id="chart" style="width: 100vw; height: 100vh;">
<script src=""></script>
<script src="app.js"></script>

The js code (app.js):

var mychart = document.getElementById('chart');
 gChart = echarts.init(mychart);
 var option = {
   tooltip : {
     formatter: "{a} <br/>{b} : {c}%"
   toolbox: {
     show : true,
     feature : {
       restore : {show: true},
       saveAsImage : {show: true}
 series : [
     name:'Business Indicators',
     detail : {
     data:[{value: 75, name: 'Rate'}]

//Add this to have the data changed every two seconds
setInterval(function () {
 option.series[0].data[0].value = (Math.random() * 100).toFixed(2) - 0;
 gChart.setOption(option, true);

  • Here first we are setting variable “mychart” to DOM element with ID = “chart”
  • At line 2 of the JS we initialize an echart at the DOM ID (“chart”)
  • Now we set the options which will be passed to the initialized echart to render on screen

Decoding the “options”:

  • In the example , options has the following attributes
    • series
    • tooltip
    • toolbox


Here we define the

  • name of chart – ‘Business Indicators’ in the example
  • type of chart – ‘Gauge’
  • Title (“Rate” in this example)  takes its value from and the styling is driven by series.title properties 
  • startAngle is 180 and endAngle is 0 (see pic) when property clockwise is set to true (default)
  • is displayed with style and positioning defined by series.details
  • pointer and axis ticks have visbility set to true.



  • Here we define the content to be seen when hovering over the pointer.
  • In line 33 of JS code ,
    • {a} represents name of the chart, defined in property (“Businesss Indicators”)
    • {b} represents
    • {c} represents data.value

Note : There are more options to customize ( described in API documentation of echarts)

Tool Box:

  • Here two features are defined to be visible -> Restore and Download as Image.
  • There are other options that can be configured

Heres the output:

Just by changing the startAngle and/or endAngle you can change the shape of the dial.

Ex, set startAngle to 225 and endAngle to -45 and here’s what you get:


Posted in Charts n Graphs, Generic, JS Frameworks, Web Technology

eCharts (v3) Simple Bar Chart

I have been playing around with javascript based charting libraries. I like HighCharts. Its pretty good for the charts you will need with very good customization features. It, however is not free (for commercial uses).

D3 library is good for creating your own charting solutions and there are a pretty good charting libraries out there built on top of D3. Personally am a big fan of the D3 library and Mike Bostock.

However recently I came across eCharts (version 3) (owned by Baidu) and was blown away by the examples in its gallery. Its based on ZRender which is a lightweight canvas library.

Its definitely something I will use over highcharts in my next project.

Here’s a list of things that made me try it :

  • A very rich gallery where you can play around as well -> Demo Gallery
  • Canvas based*
  • Very well documented -> API Docs
  • It also has a offline chart builder.
  • Free. Yes you can simply get the minified js and start using it.

Note : A lot of people indicated that the documentation is difficult as it is mostly in chinese. As of today I did not find that to be a hindrance and the documentation I read was in plain English.

Here’s the CDN for the english version of echarts version 3

Do give it a try.

Here’s a sample application :

The js code (app.js):

var chartdata=[
     name: 'Oranges',    
     type: 'bar',    
     data: [20, 20, 36, 12, 15, 20]    
     name: 'Apples',    
     type: 'bar',    
     data: [8, 5, 25, 10, 10, 13]    
     name: 'Strawberries',    
     type: 'bar',    
     data: [8, 5, 20, 10, 7, 15]    
     name: 'Mangoes',    
     type: 'bar',    
     data: [8, 5, 20, 10, 7, 15]    

var legendData ={return;});

var chart = document.getElementById('chart');    

var myChart = echarts.init(chart);  
var option = {    
               title: { 
                        text: 'eCharts:Bar',                 
               toolbox: {
                         show : true,
                         feature : {            
                                     dataView : {show: true, title:'Data View', readOnly: false},            
                                     magicType : {show: false, title:['line','bar'],type: ['line', 'bar']},            
                                     restore : {show: true, title:'Restore'},            
                                     saveAsImage : {show: true, title:"Save As Image"}        
               tooltip: {                   
               legend: { 
                         data: [ 'Oranges','Apples','Strawberries','Mangoes' ]
               xAxis: { 
                        data: [ "2006", "2008", "2010", "2012", "2014", "2016" ]
               yAxis: { },    
               series: chartdata,          
               backgroundColor:'rgba(0, 0, 0, 1)',          
               color:[ '#FF9800','#ef5350','#F48FB1','#81C784','#c4ccd3','#c23531','#2f4554','#61a0a8','#d48265','#91c7ae']

The HTML Code(index.html):

<!doctype html>
<title>Charts BarChart Example</title>
<div id="chart" style="width: 100vw; height: 100vh;">
<script src=""></script>
<script src="app.js"></script>

And here’s the output (Its interactive and you can toggle the series via the legends) :



Github repo :

Codepen link :

Pretty interesting. I will be playing around more with echarts and vue.

Posted in Charts n Graphs, Generic, JS Frameworks, Web Technology

Switch to Yarn (from npm)

I switched to yarn from npm cause it does everything that npm does (almost everything and more) , only faster.

And by faster I mean, really really fast, like ultrafast.

What is yarn, anyways?
Its a package manager for your code (just like npm) from Facebook.

How to install yarn on your OSX?
brew install yarn
This will also install node.

Use this if you want to skip installing node.
brew install yarn --without-node

You could also use npm itself to install yarn ( and then switch to yarn completely )
npm i -g yarn


If you already have yarn and would like to upgrade to the latest version :

brew upgrade yarn

If you are already familiar with npm heres a list of commands that can help you switch to yarn faster:

here will be a table

Example of “yarn why <package>”

Pretty useful command to get package details and info

nsingh$ yarn why babel-core
yarn why v0.27.5
[1/4] Why do we have the module "babel-core"...?
[2/4] Initialising dependency graph...
[3/4] Finding dependency...
[4/4] Calculating file sizes...
info Has been hoisted to "babel-core"
info Reasons this module exists
- "babel-core#babel-register" depends on it
- Specified in "devDependencies"
info Disk size without dependencies: "228kB"
info Disk size with unique dependencies: "8.25MB"
info Disk size with transitive dependencies: "17.06MB"
info Number of shared dependencies: 28
Done in 0.91s

Screenshot of “yarn upgrade-interactive v0.27.5 “







Speed Test : npm vs yarn

npm install took 26 secs

yarn install tool 9.95 secs

(Note : I will be updating this page as and when needed)



Posted in Generic, Web Technology

Hit Counter provided by technology news