javascript - 如何更改圆环图中文本的颜色

标签 javascript css highcharts donut-chart

如何更改圆环图中的特定文本颜色

示例:“10% Need Action”,我需要将 10% 更改为红色。

我已将文字包含在圆环图中。 我正在尝试如上所述更改文本的颜色。

这是我的代码

$(function () 
    {
        $('#dc-target-fill-rates').highcharts({
           chart: {
               type: 'pie',

                  },
        credits: {
            enabled: false
        },
        exporting: {
            buttons: {
                contextButtons: {
                    enabled: false,
                    menuItems: null
                }
            },
            enabled: false
        },
        title: {
            verticalAlign: 'middle',
            floating: true,
            text: "<span><b>10%</b><br/>Need Action</span>",
            style: { color: '#60727d', fontSize: '15px', fontFamily: 'Avenir LT Std Light' },
            x: 0,
            y: -5
        },
        subtitle: {
            //text: '3D donut in Highcharts'
        },

        tooltip: {
            style: { fontFamily: 'Avenir LT Std Heavy' },
            shadow: false,
            useHTML: true,
            backgroundColor: 'rgba(255, 255, 255, 0.85)',
            borderColor: '#a9a9a9',
            headerFormat: "",
            pointFormat: '<span style="color: {point.color}">●</span><span style="color: {point.color}">  {point.name}</span> : <b>{point.percentage:.2f}%</b>'
        },
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                innerSize: '80%',
                //depth: 45,
                shadow: false,
                dataLabels: {
                    enabled: false,
                    format: '<b>{point.name}</b>: {point.percentage:.1f} %',
                    style: {
                        color: 'black'
                    }
                }
            }
        },
        series: [{
            name: 'Brands',
            colorByPoint: true,
            data: [{
                name: 'Need Action',
                y: 5,
                color: '#fc5d45'
            }, {
                name: 'At Risk',
                y: 10,
                color: '#ffd52f'

            }, {
                name: 'On Track',
                y: 50,
                color: '#5db567'
            }]
        }]
    });
});

最佳答案

更改 fill.highcharts-title tspan。引用https://jsfiddle.net/hrv3tfzs/

将此样式添加到您的 CSS

.highcharts-title tspan {
  fill: red;
}

关于javascript - 如何更改圆环图中文本的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37134571/

相关文章:

javascript - 对如何在node.js中实现异步回调感到困惑

javascript - MongoDB : missing ; before statement with for instruction

javascript - 使用 jQuery 显示隐藏图像

php - 单击时为 Highcharts 生成有效的 JSON

javascript - 在 Highcharts 中使用 pointPadding 更改条形宽度

javascript - HighCharts 导出文件名

javascript - 空并在 html 页面上放置外部 javascript

javascript - 如果所有浏览器都使用同源策略,CSRF 攻击如何发挥作用?

javascript - 存储文本输入并显示在页面上

php - Wordpress wp_enqueue 加载 css 但不加载 js