简体   繁体   English

highcharts-不显示饼图图例

[英]highcharts - pie chart legend not displayed

My series data is as follows:- 我的系列数据如下:-

[{"name":"Calculated Profit","data":[{"y":90,"rowData":{"Salesperson":"Dr. Gary Barlow","EP":90.00000,"AP":390.00000,"CP":90.00000,"Retries":1}},{"y":90,"rowData":{"Salesperson":"Fr. G R Blue","EP":90.00000,"AP":390.00000,"CP":90.00000,"Retries":1}},{"y":3332.8908,"rowData":{"Salesperson":"Miss Lynsey A Carr","EP":3332.89080,"AP":9252.84214,"CP":3332.89080,"Retries":3}},{"y":157.5,"rowData":{"Salesperson":"Mr. G WALTON","EP":157.50000,"AP":472.50000,"CP":157.50000,"Retries":1}},{"y":90,"rowData":{"Salesperson":"Mr. Jason Orange","EP":90.00000,"AP":390.00000,"CP":90.00000,"Retries":1}},{"y":3746.35416,"rowData":{"Salesperson":"Mr. Joe Bloggs","EP":3746.35416,"AP":11239.06249,"CP":3746.35416,"Retries":1}},{"y":90,"rowData":{"Salesperson":"Prof. Howard Donald","EP":90.00000,"AP":390.00000,"CP":90.00000,"Retries":1}},{"y":90,"rowData":{"Salesperson":"Prof. T V Smith","EP":90.00000,"AP":390.00000,"CP":90.00000,"Retries":1}},{"y":90,"rowData":{"Salesperson":"RtHon. H Q Brown","EP":90.00000,"AP":390.00000,"CP":90.00000,"Retries":1}}]}]

My chart plotOptions are as follows:- 我的图表plotOptions如下:

plotOptions: {

                        pie: {
                            allowPointSelect: true,
                            cursor: 'pointer',
                            dataLabels: {
                                enabled: true
                        },
                        tooltip: {
                            pointFormat: '{series.data.rowData.Salesperson}: <b>{point.percentage}%</b>',
                            percentageDecimals: 1
                        },
                        showInLegend: true

                }

Any pointers .. as Legend displayed as {series.data.rowData.Salesperson} 图例中的所有指针..显示为{series.data.rowData.Salesperson}

Unfortunately you need to use tooltip.formatter , not pointFormat. 不幸的是,您需要使用tooltip.formatter ,而不是pointFormat。 PointFormat is simple regexp which checks out only first element after point/series and compares as key with point/series object. PointFormat是简单的正则表达式,它仅检出点/系列之后的第一个元素,并与点/系列对象作为键进行比较。

In order to set the legend labels as the Salesperson, you can use the legend.labelFormatter callback function on the same level as chart, see full link to fiddle 为了将图例标签设置为销售人员,可以在与图表相同的级别上使用legend.labelFormatter回调函数,请参见小提琴的完整链接

  legend: {
    labelFormatter: function() {
      return this.rowData.Salesperson;
    }
  },
  tooltip: {
    formatter: function() {
        return '<b>' + this.point.rowData.Salesperson + '</b> ' + Highcharts.numberFormat(this.point.percentage, 1) +' %';
    },
    percentageDecimals: 1
  },
  plotOptions: {
    pie: {
      allowPointSelect: true,
      cursor: 'pointer',
      dataLabels: {
        enabled: true,
        formatter: function() {
          return this.point.rowData.Salesperson;
        }
      },
      showInLegend: true
    }
  }

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

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