2016-12-14 52 views

回答

0

,如果使用已經它採用了彩色軸Highcharts模塊,你可以使用它的tweenColors功能找到的中間色。

如前所述,您必須遍歷數據並設置點的顏色。如果你不想使用任何其他模塊,你需要找到中間顏色 - 答案可以找到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) 
    }; 
}); 

例如:http://jsfiddle.net/oudktg0o/