全部,
我在我正在开发的网络应用程序中使用 Highcharts。其中一项要求是用户应该能够单击按钮并“翻转”或反转 Y 轴。
换句话说 - 当用户点击一个按钮时 - y 轴值应该从:
highest at the top / lowest at the bottom
到
lowest at the top / highest at the bottom
当您第一次创建图表时 - 这可以使用 y 轴的“反向”属性:
http://api.highcharts.com/highcharts#yAxis.reversed
此处示例:http://jsfiddle.net/ZgVNS/
但是 - 如果我尝试使用选项对象通过 JavaScript 以编程方式执行此操作(例如,单击按钮),它似乎不起作用:
chart.options.yAxis.reversed = !chart.options.yAxis.reversed;
chart.redraw();
这是我设置用于测试的 jsfiddle:http://jsfiddle.net/4JZxS/6/
这可能吗?
提前致谢!
最佳答案
您可以使用 Axis.update() 方法:
$(function () {
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container'
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
yAxis: {
reversed: false
},
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]
}]
});
var reversed = chart.options.yAxis.reversed;
// the button action
$('#button').click(function () {
chart.yAxis[0].update({
reversed: !reversed
});
reversed = !reversed;
});
});
这是更新后的 JSFiddle:http://jsfiddle.net/4JZxS/15/
关于javascript - Highcharts - 以编程方式 "flip"(反向)Y 轴,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14205701/