Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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,
  }
 }
},
like image 400
repincln Avatar asked Oct 25 '12 11:10

repincln


2 Answers

Try:

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

etc.

like image 185
Asad Saeeduddin Avatar answered Oct 04 '22 15:10

Asad Saeeduddin


You also use zones:

$(function () {
    $('#container').highcharts({
        series: [{
            data: [-10, -5, 0, 5, 10, 15, 10, 10, 5, 0, -5],
            zones: [
              {
                value: 0,
                color: '#f7a35c'
              }, 
              {
                color: '#90ed7d'
              }
            ]
        }]
    });
});

Try it in jsfiddle.net

like image 39
Ivan Nack Avatar answered Oct 04 '22 15:10

Ivan Nack