简体   繁体   English

Highcharts图例颜色与饼图切片颜色相同

[英]Highcharts same legend color as of the pie chart slice color

Hi i am working on highcharts pie chart, i am showing legend with the chart. 嗨,我正在研究highcharts饼图,我在图表中显示图例。 i want to show legend color same as of the each slice color. 我想显示与每个切片颜色相同的图例颜色。 currently each legend color is same. 目前,每个图例颜色都是相同的。 here is my code 这是我的代码

 <script src="text/javascript">
      Highcharts.theme = {
         colors: ['#058DC7', '#50B432', '#FFC000', '#ED561B', '#DDDF00', '#64E572', '#FF9655', '#FFF263', '#6AF9C4'],
        chart: {
            backgroundColor: {
                linearGradient: [0, 0, 500, 500],
                stops: [
                    [0, 'rgb(255, 255, 255)'],
                    [1, 'rgb(240, 240, 255)']
                ]
            }
        }
    }; 

var highchartsOptions = Highcharts.setOptions(Highcharts.theme);

        var chart;

        chart = new Highcharts.Chart({
            chart: {
                renderTo: 'holdingPie',
                plotBackgroundColor: null,
                plotBorderWidth: null,
                plotShadow: false,
                spacingBottom: 0,
                margin: [0, 0, 0, 40]
            },
            title: {
                text: ''
            },
            credits: {
                enabled: false
            },
            tooltip: {
                formatter: function () {
                    return '<b>' + this.point.name + '</b>: ' + roundNumber(this.percentage, 2) + ' %' + ' of total holding value';
                },
                style: {
                    fontSize: '11px'
                }
            },
            plotOptions: {
                pie: {
                    allowPointSelect: true,
                    cursor: 'pointer',
                    dataLabels: {
                        enabled: false
                    },
                    showInLegend: true
                }
            },
            legend: {
                enabled: true,
                layout: 'vertical',
                float: true,
                style: {
                    left: '0px',
                    bottom: 'auto',
                    right: 'auto',
                    top: '0px',
                    margin: '0px',
                    padding: '5px'
                }
            },
            series: [{
                    type: 'pie',
                    name: 'Holdings'
  <?php piedata(); ?>
                   }]
          });
}

piedata() is the function that gets data from database. piedata()是从数据库获取数据的函数。 i have searched it but could not find anything relevant. 我已经搜索过了,但是找不到任何相关的信息。 Is there any option in highchart api to show legend in same color as of the pie slice or any other way to do this. highchart api中是否有任何选项以与饼图相同的颜色显示图例或其他任何方式。

Using your code , I have created a fiddle. 使用您的代码,我创建了一个小提琴。 I used data from another fiddle as your data was not here. 我使用了另一个小提琴中的数据,因为您的数据不在这里。 One more change I made is that , in legends I kept enabled:true only and removed all styles. 我进行的另一项更改是,在图例中,我保持启用状态:true,仅删除所有样式。 Your legends were coming on the pie that could be the reason your legend's color might not be distinguished . 您的传说即将来临,这可能是您的传说的颜色可能无法区分的原因。

 legend: {
            enabled: true /*,
            layout: 'vertical',
            float: true,
            style: {
                left: '0px',
                bottom: 'auto',
                right: 'auto',
                top: '0px',
                margin: '0px',
                padding: '5px'
            }*/
        }

See my the working Fiddle here 在这里看到我正在工作的小提琴

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

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