Highchart的仪表带有梯度绘图带

时间:2013-03-21 02:21:51

标签: highcharts

我正在尝试使用Highcharts规格。有没有办法将绘图带设置为线性渐变?如果我的仪表的值为0-100,我希望绘图带从0处的红色变为50处的黄色变为100处的绿色。

我认为我可以为每个停止点生成单独的plotband部分,1-100但是如果有办法设置一个更加清洁的线性隆起。有人知道吗?

2 个答案:

答案 0 :(得分:4)

是的,有可能。尝试这样的事情:

yAxis: {
        min: 0,
        max: 100,
        plotBands: [{
            color: {
                linearGradient:  [300, 300, 0, 0],
                stops: [
                    [0, 'rgb(255, 255, 255)'],
                    [1, 'rgb(150, 200, 155)']
                ]
            },
            from: 0,
            to: 100
        }],
    },

http://jsfiddle.net/fsQZ7/

通过仔细选择颜色,linearGradients和from / to,你应该能够组合几个绘图带来做你想要的。

答案 1 :(得分:1)

上阅读“LINEAR GRADIENTS”

http://www.highcharts.com/docs/chart-design-and-style/colors

示例:从黄色到绿色再到红色:

plotBands: [{
    from: 0,
    to: 29,
    color: '#DDDF0D' // yellow
},{
    from: 29,
    to: 40,
    color: {
        linearGradient:  { x1: 0, x2: 0, y1: 0, y2: 1 },
        stops: [
            [0, '#55BF3B'], //green
            [1, '#DDDF0D'] //yellow
        ]
    }
}, {
    from: 40,
    to: 51,
    color: {
        linearGradient:  { x1: 0, x2: 0, y1: 0, y2: 1 },
        stops: [
            [0, '#55BF3B'], //green
            [1, '#DF5353'] //red
        ]
    }
}, {
    from: 51,
    to: 80,
    color: '#DF5353' //red
}]