repincln repincln - 7 months ago 136
Javascript Question

conditional marker colors in highcharts

I'm using Highcharts and I want to fill markers in line chart with different colors. For example: when variable "a" is 1 then fill marker with red else fill with green. Is it possible to do that?

Here is the code: http://jsfiddle.net/EnyCJ/1/

I was trying to do that with formatter but it doesn't work. Any suggestions?

var a=1;

plotOptions: {
series: {
marker: {
fillColor: {
formatter: function () {
if (a == 1) {
return 'red'
} else {
return 'green'
}
}
},
lineWidth: 2,
}
}
},

Answer

Try:

fillColor: a==1 ? "#ff0000" : "#00ff00"

etc.