I am working on highcharts and I have problem with legend. I have 4 columns in legend of pie chart and need to give headings to each of these columns. I am using following code and result is given below.
useHTML: true,
labelFormatter: function () {
return '<div style="width:800px"><span style="float:left;width:200px">' + this.name + '</span><span>'
+ this.description + '</span><span style="float:right;width:100px">' + this.target + '</span><span style="float:right;width:100px">' + Highcharts.numberFormat(this.y, 0) + '%</span></div>';
}
You can disable a legend formatter and then prepare your own HTML legend, creating a style which you need. Example of simple HTML legend:
$legend = $('#customLegend');
$.each(chart.series[0].data, function (j, data) {
$legend.append('<div class="item"><div class="symbol" style="background-color:'+data.color+'"></div><div class="serieName" id="">' + data.name + '</div></div>');
});
$('#customLegend .item').click(function(){
var inx = $(this).index(),
point = chart.series[0].data[inx];
if(point.visible)
point.setVisible(false);
else
point.setVisible(true);
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.