Highcharts solidgauge : How can I disable gradient fill?

后端 未结 3 782
孤街浪徒
孤街浪徒 2021-01-12 15:08

I\'m trying to use Highcharts new solidgauge plugin.

http://jsfiddle.net/4zVU8/2/

source code as provided by highchart

相关标签:
3条回答
  • 2021-01-12 15:48
    // change your stops ,0 and 1 set the same value
    var showNumber = 100; // your random data
    var tickMaxNumber = 1000; // The yAxis max value 
    if(showNumber <= tickMaxNumber*0.2){
        gaugeOptions.yAxis[0].stops = [ // red
            [0, '#EE4B4B'],
            [1, '#EE4B4B']
        ];
    }else if(showNumber <= tickMaxNumber*0.8){
        gaugeOptions.yAxis[0].stops = [ // yellow
            [0, '#FFC063'],
            [1, '#FFC063']
        ];
    }else{
        gaugeOptions.yAxis[0].stops = [ // green
            [0, '#40A276'],
            [1, '#40A276']
        ];
    }
    
    $('#container-speed').highcharts(gaugeOptions);
    
    0 讨论(0)
  • 2021-01-12 16:01

    To get a solid color, set the minColor and maxColor options to the same value. To set the color based on a value, just compare in the options:

    var guageValue = 60;
    
    var gaugeOptions = {
    
      ...
    
    yAxis: {
        minColor: guageValue >= 80 ? '#FF0000' : (guageValue >= 60 ? '#FFFF00' : '#00FF00'),
        maxColor: guageValue >= 80 ? '#FF0000' : (guageValue >= 60 ? '#FFFF00' : '#00FF00'),
        lineWidth: 0,
    
        ....
    

    EDITS FOR COMMENT

    Well, doing it dynamically according to the API should be as easy as:

    var chart = Highcharts.charts[0];
    var point = chart.series[0].points[0];
    var color = newGuageValue >= 80 ? '#FF0000' : (newGuageValue >= 60 ? '#FFFF00' : '#00FF00');
    chart.yAxis[0].update({minColor:color, maxColor:color});
    point.update(newGuageValue);
    

    But, this breaks the chart (and I believe it to be a bug in the library).

    So the best I can come up with is to go after the internals directly:

    var chart = Highcharts.charts[0];
    var point = chart.series[0].points[0];
    var color = newGuageValue >= 80 ? [255,0,0,1] : (newGuageValue >= 60 ? [255,255,0,1] : [0,255,0,1]);
    chart.yAxis[0].stops[0].color.rgba = color;
    chart.yAxis[0].stops[1].color.rgba = color;
    point.update(newGuageValue);
    

    Here's a fiddle demo.

    0 讨论(0)
  • 2021-01-12 16:04

    You can set stops, like this: http://jsfiddle.net/4zVU8/5/

            stops: [
                [0.0, '#55BF3B'], // green
                [0.2, '#55BF3B'], // green
                [0.21, '#DDDF0D'], // yellow
                [0.80, '#DDDF0D'], // yellow
                [0.81, '#DF5353'], // red
                [1, '#DF5353'] // red
            ]
    

    So aright after color ends set new color.

    0 讨论(0)
提交回复
热议问题