Highchart pie legend circles

2020-03-05 06:06发布

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...

enter image description here

4条回答
Viruses.
2楼-- · 2020-03-05 06:59

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.

查看更多
对你真心纯属浪费
3楼-- · 2020-03-05 06:59

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.

查看更多
聊天终结者
4楼-- · 2020-03-05 07:07

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;
}
查看更多
干净又极端
5楼-- · 2020-03-05 07:11

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

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

查看更多
登录 后发表回答