简体   繁体   中英

How to render multi line chart with DC.js with the following type of data - JAVASCRIPT (DC.js)

Following is the set of data:

var data = [{
 machine1: [
  {x:"20/12/2014", y:2}, {x:"21/12/2014", y:10}
 ]},{
 machine2: [
  {x:"20/12/2014", y:23}, {x:"21/12/2014", y:46}
 ]
}];

Need to implement dc.js for the above data Each machine will have individual line on a chart. Thanks for the help

Crossfilter works best with a flat array of observations. It looks like your data might best be represented by observations (rows) of {machine, x, y}

It's hard to tell with the example you've given, because it is very deeply nested but many of the levels are unused, exactly what the format is. I'd advise you to either flatten it out when you're producing it, or if you have no control over that, loop over it and produce an array of just the deepest {x,y} objects, but annotate them with the machine id from the level above that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM