我的 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.
});
});
希望您能够帮助我。