shutterstock / rickshaw

JavaScript toolkit for creating interactive real-time graphs
https://shutterstock.github.io/rickshaw
MIT License
6.53k stars 941 forks source link

more compact data series #3

Closed defunctzombie closed 12 years ago

defunctzombie commented 12 years ago

Is it possible to submit the data series as just an array of x,y?

[ [x,y], [x,y] ]

This avoids the need to send all of the duplicate x, y back from the server.

jnav commented 12 years ago

why don't you just create simple function which is going to convert it on the fly?

see source code here: http://code.shutterstock.com/rickshaw/examples/status.html

this code goes through array and pushes objects with data into statusCounts array which is then used as source for chart

function transformData(d) {
    var data = [];
    var statusCounts = {};

    Rickshaw.keys(d).sort().forEach( function(t) {
        Rickshaw.keys(d[t]).forEach( function(status) {
            statusCounts[status] = statusCounts[status] || [];
            statusCounts[status].push( { x: parseFloat(t), y: d[t][status] } );
        } );
    } );

little example:

var mydata = []
mydata = [ [1, 2] , [2,8] , [3,12] ];

function transformMyData(d){
  var tempData = [];
  Rickshaw.keys(d).forEach( function(t) {
    console.log(d[t][0]);
    tempData.push( { "x": d[t][0], "y": d[t][1] } );
  });
  return tempData;
}

var result = transformMyData(mydata);

so your result variable will contain data ready to be passed to graph