javascript - Highcharts - programmatically "flip" (reverse) Y Axis - Stack Overflow

All,I'm using Highcharts in a web app I'm working on. One of the requirements is that users s

All,

I'm using Highcharts in a web app I'm working on. One of the requirements is that users should be able to click a button and "flip" or reverse the Y axis.

In other words - when the user clicks a button - the y Axis values should flip from:

highest at the top / lowest at the bottom

to

lowest at the top / highest at the bottom

When you first create the chart - this is possible using the "reversed" property of the y Axis:

.reversed

Example here: /

However - if I attempt to do this programmatically with JavaScript using the options object (e.g., on a button click), it doesn't seem to work:

chart.options.yAxis.reversed = !chart.options.yAxis.reversed;
chart.redraw();

Here's a jsfiddle I set up to test: /

Is this possible?

Thanks in advance!

All,

I'm using Highcharts in a web app I'm working on. One of the requirements is that users should be able to click a button and "flip" or reverse the Y axis.

In other words - when the user clicks a button - the y Axis values should flip from:

highest at the top / lowest at the bottom

to

lowest at the top / highest at the bottom

When you first create the chart - this is possible using the "reversed" property of the y Axis:

http://api.highcharts./highcharts#yAxis.reversed

Example here: http://jsfiddle/ZgVNS/

However - if I attempt to do this programmatically with JavaScript using the options object (e.g., on a button click), it doesn't seem to work:

chart.options.yAxis.reversed = !chart.options.yAxis.reversed;
chart.redraw();

Here's a jsfiddle I set up to test: http://jsfiddle/4JZxS/6/

Is this possible?

Thanks in advance!

Share Improve this question asked Jan 7, 2013 at 23:07 mattstuehlermattstuehler 9,33218 gold badges81 silver badges115 bronze badges 2
  • @oftopic: It's my jsfiddle or it's not showing loaded code ? – Ricardo Lohmann Commented Jan 8, 2013 at 2:03
  • @RicardoLohmann Mine is not working at Chrome. In firefox I can see the code. – Felipe Fonseca Commented Jan 8, 2013 at 11:45
Add a ment  | 

2 Answers 2

Reset to default 6

You can use the Axis.update() method:

$(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;
   });
});

Here's the updated JSFiddle: http://jsfiddle/4JZxS/15/

I don't think it's possible.

My advice is to destroy the chart using chart.destroy() and create the new one with the reversed property, like in this fiddle

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744805645a4594760.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信