首页 > 解决方案 > Highcharts - 如何动态设置饼图的背景颜色

问题描述

我正在使用以下行根据某些条件更改一些视觉属性

this.$refs.pieChart.chart.series[0].update({ dataLabels: { color: 'blue' }, chart: { backgroundColor: 'yellow' } })

这适用于 dataLabels 部分,但我无法更改 backgroundColor 之一。

我试过这个:

this.$refs.pieChart.chart.series[0].update({ dataLabels: { color: 'blue' }, backgroundColor: 'yellow' })

和这个

this.$refs.pieChart.chart.series[0].update({ backgroundColor: 'yellow' })

没有运气,我在我的代码中搜索了其他任何地方,没有任何东西可以覆盖或设置背景 颜色。

标签: vue.jschartshighcharts

解决方案


您应该更新整个图表配置,而不是系列:

chart.update({
    chart: {
        backgroundColor: 'red'
    }
})

API:https ://api.highcharts.com/highcharts/chart.backgroundColor

API:https ://api.highcharts.com/class-reference/Highcharts.Chart#update

演示:https ://jsfiddle.net/BlackLabel/p7yg386x/


推荐阅读