所有
我在我正在使用的网络应用中使用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/
这可能吗?
提前致谢!
答案 0 :(得分: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/
答案 1 :(得分:2)
我认为这不可能。
我的建议是使用chart.destroy()
销毁图表并使用反转属性创建新图表,例如fiddle