简体   繁体   English

HighCharts中如何将饼图中的图例作为数据标签

[英]How to have legends in Pie charts as data labels in HighCharts

I have a couple of questions while dealing with Pie Charts in High charts.在处理高图表中的饼图时,我有几个问题。

  1. How to change the legend's shape apart from the circle.除了圆形之外,如何改变图例的形状。
  2. I want to display legends in data labels prior to percentage values.我想在百分比值之前显示数据标签中的图例。 样本图像
  3. And also with an increase in data, data labels are not radical to the pie chart.而且随着数据的增加,数据标签对饼图来说并不激进。 How to fix this.如何解决这个问题。

my chart options:我的图表选项:

Highcharts.chart('container', {
    chart: {
        plotBackgroundColor: null,
        plotBorderWidth: null,
        plotShadow: false,
        type: 'pie'
    },
   
    tooltip: {
        pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
    },
    accessibility: {
        point: {
            valueSuffix: '%'
        }
    },
    plotOptions: {
        pie: {
            allowPointSelect: true,
            cursor: 'pointer',
            dataLabels: {
                enabled: true,
                format: '{point.percentage:.1f} %'
            },
            showInLegend: true
        },
    },
    series: [{
        name: 'Brands',
        colorByPoint: true,
        dataLabels: {
        connectorWidth : 0
        },
        showLegends: true,
        data: [{
            name: 'Chrome',
            y: 61.41,
           
        }, {
            name: 'Internet Explorer',
            y: 11.84
        }, {
            name: 'Firefox',
            y: 10.85
        }]
    }]
});

my code pen我的密码笔

Would be grateful if I get an answer to any of my questions.如果我得到任何问题的答案,我将不胜感激。

  1. The API allows customizing the legend symbol by setting options like symbolRadius or symbolHeight . API 允许通过设置symbolRadiussymbolHeight等选项来自定义图例符号。

Demo: https://jsfiddle.net/BlackLabel/1m98xgvr/演示: https://jsfiddle.net/BlackLabel/1m98xgvr/

API: https://api.highcharts.com/highcharts/legend.symbolHeight API: https://api.highcharts.com/highcharts/legend.symbolHeight

If you want to change the legend symbol to the custom png try to use this solution:如果您想将图例符号更改为自定义 png,请尝试使用此解决方案:

Custom Highcharts legend symbol 自定义Highcharts图例符号


  1. You can set the dataLabels.useHTML flag to true and use the dataLabes.formatter callback to customize the output which will be an outstanding HTML element.您可以将dataLabels.useHTML标志设置为 true 并使用dataLabes.formatter回调来自定义 output,这将是一个出色的 HTML 元素。

Demo: https://jsfiddle.net/BlackLabel/2sog3znq/演示: https://jsfiddle.net/BlackLabel/2sog3znq/


  1. Here I am not sure what do you have in mind - could you explain it more precisely?在这里我不确定你的想法是什么 - 你能更准确地解释一下吗?

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

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