ChartJS - 每个数据点的颜色不同 [英] ChartJS - Different color per data point

查看:35
本文介绍了ChartJS - 每个数据点的颜色不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法为折线图中的数据点设置不同的颜色,如果它高于某个值?

Is there a way to set a different color to a datapoint in a Line Chart if its above a certain value?

我为 dxChart 找到了这个示例 - https://stackoverflow.com/a/24928967/949195 - 现在为 ChartJS 寻找类似的东西

I found this example for dxChart - https://stackoverflow.com/a/24928967/949195 - and now looking for something similar for ChartJS

推荐答案

对于 chartjs 2.0,请参阅以下答案.

原始答案如下.

关于 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";

然后这样做:

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();
 }

无论如何都要试一试.

这篇关于ChartJS - 每个数据点的颜色不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆