Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set different colors for each column in highcharts

I need to set different colors for each column in Highcharts graph dynamically. My Highcharts graph is:

options = {          chart: {              renderTo: 'chart',              type: 'column',              width: 450          },          title: {              text: 'A glance overview at your contest’s status'          },          xAxis: {              categories: ['Approved Photos', 'Pending Approval Photos',                            'Votes', 'Entrants'],              labels: {                  //rotation: -45,                  style: {                      font: 'normal 9px Verdana, sans-serif, arial'                  }              }          },          yAxis: {              allowDecimals: false,              min: 0,              title: {                  text: 'Amount'              }          },          legend: {              enabled: false          },          series: []      };      series = {          name: "Amount",          data: [],          dataLabels: {              enabled: true,              color: '#000000',              align: 'right',              x: -10,              y: 20,              formatter: function () {                  return this.y;              },              style: {                  font: 'normal 13px Verdana, sans-serif'              }      }  }; 

The data is set this way:

for (var i in Data) {   if (parseInt(Data[i]) != 0) {     series.data.push(parseInt(Data[i]));   } else {     series.data.push(null);   } } options.series.push(series); chart = new Highcharts.Chart(options); 

How can I dynamically set different colors for each data point in this loop?

like image 224
user750487 Avatar asked Oct 12 '11 08:10

user750487


People also ask

How do you vary the fill colors of the columns by point?

On the Format tab, in the Current Selection group, click Format Selection. tab, expand Fill, and then do one of the following: To vary the colors of data markers in a single-series chart, select the Vary colors by point check box.

How do I change colors in Highcharts?

Add which colors you want to colors and then set colorByPoint to true . Reference: http://api.highcharts.com/highstock#colors. http://api.highcharts.com/highcharts#plotOptions.column.colorByPoint.

What is plot options in Highcharts?

The plotOptions is a wrapper object for config objects for each series type. The config objects for each series can also be overridden for each series item as given in the series array. Configuration options for the series are given in three levels. Options for all series in a chart are given in the plotOptions.


Video Answer


1 Answers

Here is another solution with the latest version of Highcharts (currently 3.0).

Set the colorByPoint option to true and define the color sequence that you want.

options = {     chart: {...},     plotOptions: {         column: {             colorByPoint: true         }     },     colors: [         '#ff0000',         '#00ff00',         '#0000ff'     ] } 

Here is an example based upon Highcharts Column with rotated labels demo

like image 129
Jérôme Avatar answered Sep 18 '22 15:09

Jérôme