Create a Highcharts Pie Chart Legend Inside a Table

牧云@^-^@ 提交于 2019-12-11 06:15:52

问题


Is there a way to create a Highcharts legend inside of a table? I want to be able to style the background of the legend for my Highcharts pie with alternating background colors for each element and custom borders.

I've formatted my legend like so, but cannot figure out how to embed it inside a table that I can then format.

legend: {
        layout: 'vertical',
        align: 'center',
        verticalAlign: 'bottom',
        backgroundColor: '#f3f3f3',
        borderWidth: 0,
        useHTML: true,
        itemMarginBottom: 10,
        labelFormatter: function () {
            return '<div style="width:200px"><span style="float:left">' + this.name + '</span><span style="float:right">' + this.percentage.toFixed(0) + '%</span><span style="float:right; margin-right:15%">$' + Highcharts.numberFormat(this.y, 0) + '</span></div>';
        }

    }, 

JS Fiddle: http://jsfiddle.net/hAnCr/135/

Any help would be appreciated. Thanks!


回答1:


If you want to put that legend in separate table, somewhere on a page - it's not supported.

If you want to just generate standard legend as is, but just use table instead of spans:

  • instead of return <div style="width:200px"> ... </div> use return <table> ... </table>
  • set useHTML: true


来源:https://stackoverflow.com/questions/19238706/create-a-highcharts-pie-chart-legend-inside-a-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!