我的highcharts有问题,要将x轴动态添加到由HighCharts生成的图表中。
为什么我要动态添加x轴?因为我的图表可以有无限数量的系列,但每次添加系列时我都不会完全重新生成它。
自HighCharts 3.0以来,“我们”可以动态地将x轴添加到图表中而无需重新创建它。 这是一个简化的测试,但这不起作用。 它只添加yAxis,我找不到通过相同函数添加xAxis的方法(http://api.highcharts.com/highcharts#Chart.addAxis())
$(function() {
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container9'
},
xAxis: [{
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},{},{}],
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
}]
});
console.log("Initial number of xAxis : " +chart.xAxis.length);
console.log("Initial number of yAxis : " +chart.yAxis.length);
$('#addaxis').click(function () {
// The function I use is : http://api.highcharts.com/highcharts#Chart.addAxis()
// It should works, but I can't found how
chart.addAxis({
categories: ['Mon', 'Tue', 'Thi', 'Fri']
},false);//Try the false paramater which is a boolean where true means xAxis and false means yAxis
//Neither of these two posibilities work.
chart.addAxis({
categories: ['I', 'You', 'He', 'She', 'We', 'You', 'They']
},true);//Try the true paramater
console.log("Number of xAxis : " + chart.xAxis.length); // nothing more
console.log("Number of yAxis : " + chart.yAxis.length); // 2 more yAxis, but I want just one add of xAxis
//Add a x-axis dynamically, it's what I am looking for. Thank in advance.
});
});
希望你能帮助我。