mat*_*ler 2 html javascript highcharts
所有,
我在我正在使用的网络应用程序中使用Highcharts.其中一个要求是用户应该能够单击按钮并"翻转"或反转Y轴.
换句话说 - 当用户单击按钮时 - y轴值应从以下位置翻转:
highest at the top / lowest at the bottom
Run Code Online (Sandbox Code Playgroud)
至
lowest at the top / highest at the bottom
Run Code Online (Sandbox Code Playgroud)
首次创建图表时 - 可以使用y轴的"反转"属性:
http://api.highcharts.com/highcharts#yAxis.reversed
但是 - 如果我尝试使用选项对象(例如,在按钮单击时)使用JavaScript以编程方式执行此操作,则它似乎不起作用:
chart.options.yAxis.reversed = !chart.options.yAxis.reversed;
chart.redraw();
Run Code Online (Sandbox Code Playgroud)
这是我设置测试的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;
});
});
Run Code Online (Sandbox Code Playgroud)
这是更新后的JSFiddle:http://jsfiddle.net/4JZxS/15/