【问题标题】:How do I style the series labels on a Highcharts pie chart?如何在 Highcharts 饼图中设置系列标签的样式?
【发布时间】:2019-09-30 04:58:22
【问题描述】:

我正在尝试更改饼图上系列标签的字体粗细,因为我们使用的字体的字体粗细呈现非常糟糕:粗体:

这是我迄今为止尝试过的(基于https://api.highcharts.com/highcharts/plotOptions.pie.label 的指导):

plotOptions: {
    pie: {
        label: {
            style: {
                fontWeight: 500,
            }
        }
    }
},

好像没有效果。

我将它用于我的全局 Highcharts 配置:

import * as Highcharts from "highcharts";
import * as HC_Series from 'highcharts/modules/series-label';

HC_Series(Highcharts);
Highcharts.setOptions({
    chart: {
        style: {
            fontFamily: '"Neue Helvetica W05", "M Hei HK W42", Arial, Helvetica, sans-serif',
        },
    },

});

我正在使用 Highcharts 6.2.0,highcharts-angular 2.4.0。

【问题讨论】:

    标签: javascript css angular typescript highcharts


    【解决方案1】:

    您需要更改 dataLabels 而不是 labelsDocumentation 坏了

    plotOptions: {
      pie: {
        allowPointSelect: true,
        cursor: 'pointer',
        dataLabels: {
          enabled: true,
          style: {
            fontWeight: 500,
          }
        }
      }
    },
    

    Fiddle

    【讨论】:

      【解决方案2】:

      它在情节选项下:

      plotOptions: {
          pie: {
            allowPointSelect: true,
            cursor: 'pointer',
            dataLabels: {
              enabled: true,
              format: '{point.name}: {point.percentage:.1f} %',
              style: {
                fontWeight: '100',
                color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'blue'
              }
            }
          }
        },
      

      下面的工作示例

      Highcharts.chart('container', {
        chart: {
          plotBackgroundColor: null,
          plotBorderWidth: null,
          plotShadow: false,
          type: 'pie'
        },
        title: {
          text: 'Browser market shares in January, 2018'
        },
        tooltip: {
          pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
        },
        plotOptions: {
          pie: {
            allowPointSelect: true,
            cursor: 'pointer',
            dataLabels: {
              enabled: true,
              format: '{point.name}: {point.percentage:.1f} %',
              style: {
                fontWeight: '100',
                color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'blue'
              }
            }
          }
        },
      
        series: [{
          name: 'Brands',
          colorByPoint: true,
          data: [{
            name: 'Chrome',
            y: 61.41,
            sliced: true,
            selected: true
          }, {
            name: 'Internet Explorer',
            y: 11.84
          }, {
            name: 'Firefox',
            y: 10.85
          }, {
            name: 'Edge',
            y: 4.67
          }, {
            name: 'Safari',
            y: 4.18
          }, {
            name: 'Sogou Explorer',
            y: 1.64
          }, {
            name: 'Opera',
            y: 1.6
          }, {
            name: 'QQ',
            y: 1.2
          }, {
            name: 'Other',
            y: 2.61
          }]
        }]
      });
      <script src="https://code.highcharts.com/highcharts.js"></script>
      <script src="https://code.highcharts.com/modules/exporting.js"></script>
      <script src="https://code.highcharts.com/modules/export-data.js"></script>
      
      <div id="container" style="min-width: 310px; height: 400px; max-width: 600px; margin: 0 auto"></div>

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-02-05
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多