2

全部,

我在我正在开发的网络应用程序中使用 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/

这可能吗?

提前致谢!

4

2 回答 2

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/

于 2014-01-14T10:09:20.407 回答
2

我不认为这是可能的。

我的建议是销毁图表chart.destroy()并使用 reversed 属性创建新图表,就像在这个小提琴中一样

于 2013-01-08T00:15:05.377 回答