How to do this? In highchart ..
horizontal bar with gradient.. red to gray for negative to positive values
How to do this? In highchart ..
horizontal bar with gradient.. red to gray for negative to positive values
If you use already a Highcharts module which uses a color axis, you can use its tweenColors function to find the intermediate color.
As was mentioned, you have to loop through the data and set the point's color. If you don't want to use any other module, you need to find intermediate colors - answer can be found here.
var data = [100, 50, 20, -10],
min = Math.min.apply(null, data),
max = Math.max.apply(null, data),
total = max - min,
colorMin = new Highcharts.Color('rgb(255, 0, 0)'),
colorMax = new Highcharts.Color('white'),
tweenColors = Highcharts.ColorAxis.prototype.tweenColors;
coloredData = data.map(value => {
var pos = (value - min) / total;
return {
y: value,
color: tweenColors(colorMin, colorMax, pos)
};
});
example: http://jsfiddle.net/oudktg0o/