[英]ECharts - Apply two different colors to labels on the same axis
I want to apply two different colors to the labels of the same X-axis on a chart. 我想在图表上对同一个X轴的标签应用两种不同的颜色。
I'm using Version 4.2.1 of echarts. 我正在使用版本4.2.1的echarts。 The X axis labels ranges from 0 to 1,000 in increments of 100.
X轴标签的范围为0到1,000,增量为100。
I want to make the first six labels (ie 0, 100, 200, 300, 400, 500) red; 我想把前六个标签(即0,100,200,300,400,500)变成红色; then the rest of the labels (ie 600, 700, 800, 900, 1000) blue.
然后其余的标签(即600,700,800,900,1000)蓝色。
In the official documentation it shows that we can specify ONE color to the X-axis labels through the following code: 在官方文档中,它显示我们可以通过以下代码为X轴标签指定一种颜色:
xAxis: {
name: 'Population',
axisLabel: {
textStyle: {
color: 'red'
}
},
}
I tried running a basic if function as below but it does not work. 我尝试运行一个基本的if函数如下,但它不起作用。 Not sure what variable name I should use in the if brackets.
不知道我应该在if括号中使用什么变量名。
axisLabel: {
textStyle: {
if (axisLabel < 600) {
color: 'red';
}
else {
color: 'blue';
}
}
},
axis.axisLabel.color supports function, which can be set like: axis.axisLabel.color支持函数,可以设置如下:
color: function(value, index) {
if (index < 6) {
return 'red';
}
else {
return 'blue';
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.