【问题标题】:How can I add custom styles to the legends of Pie Chart?如何向饼图的图例添加自定义样式?
【发布时间】:2022-11-23 21:11:57
【问题描述】:

我正在使用 Pie with Legends 类型的 Highchart。我的要求很简单,我只想为图例字体(颜色、字体大小、字体重量)添加一些自定义样式。我尝试使用样式属性,但它不起作用。我指的是这个饼图演示 - Demo-PieChart

我尝试使用以下方法,但它不起作用。 `

legend: {
        labelFormat: '{name}:{percentage:.1f}%',
      style: {
        color: '#b74096',
        fontSize: '12px'
      }

`

有人可以帮我解决这个问题吗?

我尝试使用样式属性,但它不起作用。我也参考了提供的 API 参考,但仍然无法解决问题。

【问题讨论】:

    标签: javascript highcharts


    【解决方案1】:

    您需要使用 itemStyle 属性:

      legend: {
        labelFormat: '{name}:{percentage:.1f}%',
        itemStyle: {
          color: '#b74096',
          fontSize: '12px'
        }
      }
    

    现场演示:https://jsfiddle.net/BlackLabel/0r4ynsx5/

    接口参考:https://api.highcharts.com/highcharts/legend.itemStyle

    【讨论】:

      猜你喜欢
      • 2021-01-05
      • 2014-10-08
      • 2019-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-08
      • 1970-01-01
      相关资源
      最近更新 更多