Reputation: 9332
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.com/highcharts#yAxis.reversed
Example here: http://jsfiddle.net/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.net/4JZxS/6/
Is this possible?
Thanks in advance!
Upvotes: 2
Views: 3287
Reputation: 716
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.net/4JZxS/15/
Upvotes: 6
Reputation: 1129
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
Upvotes: 2