Highcharts Demo
author(s):
Torstein Hønsi
by J. Albert Bowden
HTML
<script src="http://code.highcharts.com/highcharts.js"></script>
<div id="container" style="height: 400px"></div>
<button id="updateLegend">Remove Legend</button>
<div id="legendMessage"></div>
JavaScript
$(function () {
var chart = $('#container').highcharts({
chart: {},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
yAxis: {
title: {
margin: 60
}
},
legend: {
enabled: true,
align: 'right',
verticalAlign: 'middle'
},
credits: {
enabled: false
},
series: [{
data: [29900, 71500, 106400, 129200, 144000, 176000, 135600, 148500, 216400, 194100, 95600, 54400]
}]
}).highcharts();
$('#updateLegend').on('click', function (e) {
var enable = !chart.options.legend.enabled;
chart.options.legend.enabled = enable;
$(this).text(enable ? 'Remove Legend' : 'Add Legend');
if (!enable) {
chart.legend.destroy();
} else {
var allItems = chart.legend.allItems;
for (var i = 0; i < allItems.length; i++) {
var item = allItems[i];
item.legendItem.add();
item.legendLine.add();
item.legendSymbol.add();
}
chart.legend.render();
}
$('#legendMessage').html('Value of <code>chart.options.legend.enabled</code>: ' + chart.options.legend.enabled);
});
});