1 回答
TA贡献1862条经验 获得超7个赞
dataSource将数据分配到data图表对象的数组中,而不是像代码的其余部分那样分配到系列中。您需要挂钩数据源的parseended事件并使用现有beforedatavalidated代码处理每个系列。您还需要跟踪idcreateSeries 方法中的值,因为它在事件中不可用parseended:
chart.dataSource.events.on('parseended', function(ev){
// process parsed data into each series' data array
ev.target.component.series.each(function(series) {
var source = ev.target.data;
var data = [];
for(var i = 0; i < source.length; i++) {
var row = source[i];
if (row.domain == series.id) {
data.push(row);
}
}
series.data = data;
});
// clear out data array so that it isn't re-assigned to the chart
// data array
ev.target.data = [];
});
// ...
function createSeries(field, name, id) {
var series = chart.series.push(new am4charts.LineSeries());
series.dataFields.valueY = "hits";
series.dataFields.dateX = "date";
series.id = id; //store id for later
series.name = name;
series.tooltipText = "{dateX}: [b]{valueY}[/]";
series.strokeWidth = 2;
var bullet = series.bullets.push(new am4charts.CircleBullet());
bullet.circle.stroke = am4core.color("#fff");
bullet.circle.strokeWidth = 2;
return series;
}
添加回答
举报