ChartJS - 每个数据点的不同颜色 [英] ChartJS - Different color per data point
问题描述
有没有一种方法来设置不同的颜色的数据点的折线图如果超过一定的值?
Is there a way to set a different color to a datapoint in a Line Chart if its above a certain value?
我发现这个例子dxChart - http://stackoverflow.com/a/24928967/949195 - 现在寻找类似的东西ChartJS
I found this example for dxChart - http://stackoverflow.com/a/24928967/949195 - and now looking for something similar for ChartJS
推荐答案
有关ChartJS问得好。我一直想要做类似的事情。即点颜色动态变化,以不同的颜色。你有没有试过低于这个。我只是尝试它,它为我工作。
Good question regarding ChartJS. I've been wanting to do a similar thing. i.e dynamically change the point colour to a different colour. Have you tried this below. I just tried it and it worked for me.
试试这个:
myLineChart.datasets[0].points[4].fillColor = "rgba(000,111,111,55)" ;
或者试试这个:
myLineChart.datasets[0].points[4].fillColor = "#FF0000";
甚至这样的:
myLineChart.datasets[0].points[4].fillColor = "lightgreen";
然后做到这一点:
Then do this:
myLineChart.update();
我想你可以有这样的事情;
I guess you could have something like;
if (myLineChart.datasets[0].points[4].value > 100) {
myLineChart.datasets[0].points[4].fillColor = "lightgreen";
myLineChart.update();
}
给它一个想试试。
Give it a try anyway.
这篇关于ChartJS - 每个数据点的不同颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!