Home Forums Chart Support how to change color of column in column chart based on values

how to change color of column in column chart based on values

Viewing 2 posts - 1 through 2 (of 2 total)
  • #26999

    I want a column graph whose column colors should change bases on values

    #27007

    @shweta-jagtap,

    You can change the color of column using color property of dataPoint as shown in the code snippet below –

    function setColor(chart){
    	for(var i = 0; i < chart.options.data.length; i++) {
      	dataSeries = chart.options.data[i];
      	for(var j = 0; j < dataSeries.dataPoints.length; j++){
        	if(dataSeries.dataPoints[j].y <= 0)
          	dataSeries.dataPoints[j].color = 'rgb(170, 0, 0)';
        }
      }
    }

    Also, please take a look at this JSFiddle which shows setting different colors to positive and negative values.

    Set dataPoint color based on value

    —-
    Manoj Mohan
    Team CanvasJS

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.