Chartjs-Chart.Js : How to change the color of a point, based on a third data

0👍

There are 2 errors that are happening when returning the color:

  1. when returning the colors you’re actually returning booleans, as mentioned in the comments it should just be the strings

  2. indexed is an array, so indexed==0 isn’t correct, what you actually want to do is check against the target index in indexed

Your final if should look like this:

if (indexed[context.dataIndex] == 0){return 'blue'}else{return 'red'}

I’ve also made a JSFiddle so you can see this in action

Leave a comment