Highcharts - 动态设置列宽
Highcharts - set column width dynamically
我想创建一个柱形图,其中第一列的宽度是第二列的 50%。
我的想法是读取 load-event, calculate the width and set it to the first column; the same for the redraw 事件中第二列的宽度。
这在第一次加载图表后有效,但是当我想在重绘事件中更改列宽时卡住了:调整 window 大小时,我得到了计算列"next to last" 调整大小的宽度,而不是当前宽度。
这个fiddle显示了问题:http://jsfiddle.net/u8a0oo0d/
$(function () {
$('#container').highcharts({
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
chart: {
events: {
load: function () {
this.series[0].options.pointWidth = this.series[0].barW / 2;
this.series[0].update(this.series[0].options);
},
redraw: function(event) {
console.log('redraw', this.series[0]);
this.series[0].options.pointWidth = this.series[1].barW / 2;
this.series[0].isDirty = true;
//this.series[0].update(this.series[0].options);
}
}
},
series: [{
type: 'column',
//pointWidth: 10,
data: [29.9, 71.5, 126.4, 149.2, 114.0, 126.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
},{
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],
type: 'column'
}]
});
});
我想创建一个柱形图,其中第一列的宽度是第二列的 50%。 我的想法是读取 load-event, calculate the width and set it to the first column; the same for the redraw 事件中第二列的宽度。
这在第一次加载图表后有效,但是当我想在重绘事件中更改列宽时卡住了:调整 window 大小时,我得到了计算列"next to last" 调整大小的宽度,而不是当前宽度。
这个fiddle显示了问题:http://jsfiddle.net/u8a0oo0d/
$(function () {
$('#container').highcharts({
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
chart: {
events: {
load: function () {
this.series[0].options.pointWidth = this.series[0].barW / 2;
this.series[0].update(this.series[0].options);
},
redraw: function(event) {
console.log('redraw', this.series[0]);
this.series[0].options.pointWidth = this.series[1].barW / 2;
this.series[0].isDirty = true;
//this.series[0].update(this.series[0].options);
}
}
},
series: [{
type: 'column',
//pointWidth: 10,
data: [29.9, 71.5, 126.4, 149.2, 114.0, 126.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
},{
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],
type: 'column'
}]
});
});