1 回答

TA貢獻(xiàn)1862條經(jīng)驗(yàn) 獲得超7個(gè)贊
dataSource將數(shù)據(jù)分配到data圖表對象的數(shù)組中,而不是像代碼的其余部分那樣分配到系列中。您需要掛鉤數(shù)據(jù)源的parseended事件并使用現(xiàn)有beforedatavalidated代碼處理每個(gè)系列。您還需要跟蹤idcreateSeries 方法中的值,因?yàn)樗谑录胁豢捎胮arseended:
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;
}
添加回答
舉報(bào)