AmCharts串行多个数据集

时间:2017-08-04 19:25:20

标签: amcharts

看一下文档中的不同示例,我发现在串行图表上包含多个图形(或行)的唯一方法是将数据放在一个数组中:

[{
  category: 1,
  value1: .8,
  value2: .64,
},
{
  category: 2,
  value1: .75,
  value2: -.4,    
}];

但是,如果您要同时尝试显示多个数据集,则此操作相当繁琐;有没有另一种方法可以做到这一点,你可以一次传递多个数组(这是我认为实现的样子,但事实并非如此):

[ 
// First set of data
{ category: 0, value: .5},
{ category: 1, value: .5},
{ category: 2, value: .5},
{ category: 3, value: .5},
{ category: 4, value: .3},
{ category: 5, value: 1}
],
// Second set of data
[
{ category: 0, value: .5 },
{ category: 1, value: .3 },
{ category: 2, value: .25 },
{ category: 3, value: .6 },
{ category: 4, value: .79 },
{ category: 5, value: .81 }
]],

关于如何做到这一点的任何想法?或者我是否需要切换到不同类型的图表?

1 个答案:

答案 0 :(得分:1)

This isn't possible in the regular AmCharts JavaScript Charts library. The only supported format is a single array of objects with the values consolidated by category as you've noticed. You'll have to preprocess your data beforehand.

The AmCharts Stock Chart library supports separate arrays of data in the dataSets array, however it only supports date-based data.

AmCharts.makeChart("chartdiv", {
  "type": "stock",
  "dataSets": [{
     // other properties omitted
     "dataProvider": [{
        category: "2017-08-01,
        value: 3
      }, {
        category: "2017-08-02,
        value: 2
      }, {
        category: "2017-08-03,
        value: 1
      }, // ...
     ]
  }, {
     // other properties omitted
     "dataProvider": [{
        category: "2017-08-01,
        value: 10
      }, {
        category: "2017-08-02,
        value: 9
      }, {
        category: "2017-08-03,
        value: 5
      }, // ...
     ]
  },
  // ...
  ]
  // ...
});

You can see this in action in the any of the stock chart demos.