繁体   English   中英

将标签添加到highcharts饼图图例中的列

[英]Add labels to columns in highcharts pie chart legend

我正在研究图表,我对图例有疑问。 我在饼形图的图例中有4列,并且需要为每个列指定标题。 我正在使用以下代码,结果在下面给出。

饼图-4列图例

               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>';
        }

您可以禁用图例格式器,然后准备自己的HTML图例,以创建所需的样式。 简单的HTML图例示例:

$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);
    });  

http://jsfiddle.net/N3KAC/1/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM