Skip to content Skip to sidebar Skip to footer

How To Set Pie Chart Wedge Colors Based On Wedge Values For Highcharts?

I'm building a pie chart in Highcharts: http://jsfiddle.net/y3j8ybrg/ I want to be able to set the background color of each wedge based on the value of the data that wedge represen

Solution 1:

Probably best to either pre-calculate the colors and create the data array as {x: 'empty', y: 56.00, color: '#somecolorhex',.. or to update the colors on load in a chart.events.load call. You could add the getColor() function in the data element as well but you would have to repeat the data value.

  getColor = function(val) {
    if (val >= 50) {
      return'red'
    } else {
      return'blue'
    }
  }

series: [{
  type: 'pie',
  name: 'days',
  innerSize: '90%',
  data: [{
    x: 'empty',
    y: 56.00,
    color: getColor(56.00)
  }, {
    x: 'days',
    y: 44.00,
    color: getColor(44.00)
  }]
}]

Sample jsfiddle

Post a Comment for "How To Set Pie Chart Wedge Colors Based On Wedge Values For Highcharts?"