我试图在一页中添加多个条形图,但是当它们显示时,只有最后一个被正确显示。在其他之前的图表中,未绘制条形图
每个图表我都有这 2 个变量(GraphOptionsX 和 GraphSeriesX)。
var GraphOptions0 = {
chart:{renderTo: null,type: 'bar',height: 200,width: 300},
title:{text:null},
subtitle:{text:null},
xAxis:{
categories:null
},
yAxis:{min:0,title:{text: null},labels:{overflow: 'justify'}},
tooltip:{formatter:function(){return '' + this.x + ' = ' + this.y;}},
plotOptions:{bar:{dataLabels:{enabled: true}}},
legend:{enabled: false},
credits:{enabled: false},
exporting:{enabled: false},
series:[]
};
var GraphSeries0 = {
name:"",
data:[],
point:{events:{click: null}}
};
在我生成图表之后(x = 0, 1,...):
var graphSeries = eval("GraphSeries" + x);
graphSeries.name = "GraphSeries" + x;
graphSeries.data.push({ y: parseInt(107), color: 'red' });
graphSeries.data.push({ y: parseInt(31), color: 'blue' });
graphSeries.data.push({ y: parseInt(635), color: 'green' });
graphSeries.data.push({ y: parseInt(203), color: 'yellow' });
graphSeries.data.push({ y: parseInt(2), color: 'orange' });
graphSeries.point.events.click = function() {
alert ('Category: '+ this.category +', value: '+ this.y);
}
var graphOptions = eval("GraphOptions" + x);
graphOptions.xAxis.categories = ['Category 1', 'Category 2', 'Category 3', 'Category 4', 'Category 5'];
graphOptions.chart.renderTo = 'containerChart'+x;
graphOptions.series.push(graphSeries);
new Highcharts.Chart(graphOptions);