Apexcharts-自定义棒颜色
是否可以自定义柱形图中每个条形的颜色?
这是我使用 React 获得的数据类型:
const [data, setData] = useState([{
data: [{
x: 'Apple',
y: 54,
color: '#CCCCCC'
}, {
x: 'Orange',
y: 66,
color: '#FF0000'
}]
}]);
但是这里的颜色没有应用于图表。
我也尝试过将“分布式”选项设置为 true 。
plotOptions: {
bar: {
distributed: true,
},
},
Is it possible to customise the colour of each bar in a column chart ?
This is the kind of data I'm having using React:
const [data, setData] = useState([{
data: [{
x: 'Apple',
y: 54,
color: '#CCCCCC'
}, {
x: 'Orange',
y: 66,
color: '#FF0000'
}]
}]);
But the colours here is are not applied to the chart.
I've tried with the 'distributed' option set to true as well.
plotOptions: {
bar: {
distributed: true,
},
},
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有两种方法可以实现这一目标,您非常接近他们。
1。将颜色传递给
您尝试过的数据非常相似,但是使用
fillcolor
作为密钥。2。
分布式
选项要为此起作用,它需要嵌套在
options
对象中:如果这不起作用,则值得确保那里' t任何无效的属性(例如
color
)可能引起问题。我敢肯定,您已经发现了一些示例,这些示例在 apexcharts docs 。
There are two ways to achieve this, you're very close to both of them.
1. Pass the color with the data
Very similar to what you've tried, but use
fillColor
as the key instead.2.
distributed
optionFor this to work, it needs to be nested inside the
options
object:If this doesn't work, it's worth making sure that there aren't any invalid attributes (e.g.
color
) somewhere that might be causing issues.As I'm sure you've already discovered, there are some examples of various ways to use colors in a column chart in the ApexCharts docs.