I am interested to change legend layout on click event as below
1st click horizontal - bottom
2nd click horizontal top
3rd click virtical left
4th click virtical right
Here is Link to FIDDLE
I don't know how this can be done, this is what I have tried so far.
HTML
<script src="http://code.highcharts.com/highcharts.js"></script>
<div id="container" style="height: 400px"></div>
<input id='legend' type='button' value='toggle legend'>
JAVASCRIPT
$(function () {
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
zoomType: 'xy',
marginLeft: 50,
marginBottom: 90
},
yAxis: {
reversed: true,
//min: 0,
//max: 50
},
plotOptions: {
series: {
stacking: 'normal'
}
},
xAxis: {
opposite: true
},
series: [{
name: '01-Jan-2014',
data: [
[28, 10],
[30, 0]
]
}]
});
var last = 0;
$('#legend').click(function(){
var arr = ['vertical','horizontal'];
if(last>arr.length){last=0;}
setTimeout(function() { alert(arr[last++]);},10);
chart.series[0].update({ legend: { layout: arr[last] }});
});
});
You need to use tranlsate() function which allows to move SVG elements like legend.
http://jsfiddle.net/F3cSa/1/
Here's a way to do it here. I hate resorting to setting the internal
dirty
flags but it seems to work well: