Highchart pie legend circles

て烟熏妆下的殇ゞ 提交于 2019-11-30 18:27:58

问题


Im using a highchart pie chart to create a donut chart but would like the legend icons to be circles any ideas??? Below is the mockup and the actual web version. Thanks...


回答1:


I prepared solution based on pie chart. Legend is generated on data points, automatically as HTML list. Then all elements gets colors from series, and use CSS3 to generate circle object (border-radius). As a result you need to add click event.

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

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

CSS:

    .symbol {
    width:20px;
    height:20px;
    margin-right:20px;
    float:left;
    -webkit-border-radius: 10px;
    border-radius: 10px;
}
.serieName {
    float:left;
    cursor:pointer;
}

.item {
    height:40px;
    clear:both;
}



回答2:


In recent versions of Highcharts you can use symbolWidth: width and symbolRadius: width/2 inside legend: {}.

See this JSFiddle demonstration: http://jsfiddle.net/Wzs9L/




回答3:


Another way to achieve this can be overriding the style using CSS. Simply add class below to your stylesheet:

.highcharts-legend-item rect {
    width: 12px;
    height: 12px; /* height = width */
    rx: 50%;
    ry: 50%;
}

and this would override the default style for the SVG Rectangle element.




回答4:


There's quite an easy fix. Just set the following properties in chartoptions:

chartoptions.legend.symbolHeight = 12;
chartoptions.legend.symbolWidth = 12;
chartoptions.legend.symbolRadius = 6;

For further reference, check highcharts api documentation.

Checkout this jsFiddle.



来源:https://stackoverflow.com/questions/17041490/highchart-pie-legend-circles

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