Skip to content

FastPivot.js is a simple, small, and fast JavaScript library to shift or pivot data. It has no dependencies and can be used with really large JSON data.

Notifications You must be signed in to change notification settings

techslides/FastPivot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 

Repository files navigation

FastPivot

FastPivot.js is a simple, small, and fast JavaScript library to shift or pivot data, often needed for drawing JavaScript charts and graphs. It has no dependencies, can be used with really large JSON data.

##Usage Pass an array to fastpivot which will return columns as objects with:

  • _data - contains frequency of any value in a column, used for lookup
  • _labels - contains unique values in an array, used to show labels in a chart
  • _labelsdata - frequency of values in an array, used to show data for each label in a graph

##Example Consider some tabular data

idmakecolorage
1Audi2015
2Toyotagreen2010
3Honda2013
4Audired2011
5BMWblue2012
6Audired2012
7Honda2013
8BMWblue2011
9Audired2010
10Toyotared2012

That you have in JSON:

var mydata='[{"id":"1","make":"Audi","color":"","age":2015},{"id":"2","make":"Toyota","color":"green","age":2010},{"id":"3","make":"Honda","color":null,"age":2013},{"id":"4","make":"Audi","color":"red","age":2011},{"id":"5","make":"BMW","color":"blue","age":2012},{"id":"6","make":"Audi","color":"red","age":2012},{"id":"7","make":"Honda","color":null,"age":2013},{"id":"8","make":"BMW","color":"blue","age":2011},{"id":"9","make":"Audi","color":"red","age":2010},{"id":"10","make":"Toyota","color":"red","age":2012}]';

Pass it to FastPivot:

var json = JSON.parse(mydata);
var data = fastpivot(json);

data["color"]._labels //returns ["", "green", "null", "red", "blue"]
data["color"]._labelsdata //returns [1, 1, 2, 4, 2]
data["color"]._data["red"] //returns 4

Draw Pie Chart with the data above, FastPivot, and ChartJS

About

FastPivot.js is a simple, small, and fast JavaScript library to shift or pivot data. It has no dependencies and can be used with really large JSON data.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published