带有颜色阶梯的仪表图

Gauge chart with steps of colors

如何使用 highcharts 实现此目的?厌倦了使用停止:[...] 但它不会像上图那样工作。

yAxis: {
            min: 0,
            max: 100
        },
        series: [{
            name: 'customers',
            data: [{
                color: {
//
                    linearGradient: { x1: 0, y1: 0, x2: 1, y2: 0},
                    stops: [
                        [0.1, '#009a60'],
                        [0.2, '#4aa84e'],
                        [0.3, '#92b73a'],
                        [0.4, '#c6bf22'],
                        [0.5, '#edbd02'],
                        [0.6, '#ffad00'],
                        [0.7, '#ff8c00'],
                        [0.8, '#fc6114'],
                        [0.9, '#f43021'],
                        [1.0, '#ed0022']
                    ]
                },
                y:76
            }],
            dataLabels: {
                format: '<div class="prc" style="text-align:center;"><span style="font-weight:normal; font-family:Helvetica Neue, Helvetica, Arial; font-size:52px;' +
                '#333' + '">{y}</span>'
            }
        }]

获取此字符的一种方法是使用轴线和刻度线覆盖图表以创建空白。接下来,您可以添加更多点并使用渐变不支持的颜色格式设置停止点 - 例如具有 3 位数字的十六进制颜色格式 ("#rgb")。

演示:http://jsfiddle.net/bsdtsmyb/

$(function() {

  var rawData = 94,
    data = getData(rawData);

  function getData(rawData) {
    var data = [],
      start = Math.round(Math.floor(rawData / 10) * 10);
    data.push(rawData);
    for (i = start; i > 0; i -= 10) {
      data.push({
        y: i
      });
    }
    return data;
  }

  Highcharts.chart('container', {
    chart: {
      type: 'solidgauge',
      marginTop: 10
    },
    
    title: {
      text: ''
    },
    
    subtitle: {
      text: rawData,
      style: {
        'font-size': '60px'
      },
      y: 200,
      zIndex: 7
    },

    tooltip: {
      enabled: false
    },

    pane: [{
      startAngle: -120,
      endAngle: 120,
      background: [{ // Track for Move
        outerRadius: '100%',
        innerRadius: '80%',
        backgroundColor: Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0.3).get(),
        borderWidth: 0,
        shape: 'arc'
      }],
      size: '120%',
      center: ['50%', '65%']
    }, {
      startAngle: -120,
      endAngle: 120,
      size: '95%',
      center: ['50%', '65%'],
      background: []
    }],

    yAxis: [{
      min: 0,
      max: 100,
      lineWidth: 2,
      lineColor: 'white',
      tickInterval: 10,
      labels: {
        enabled: false
      },
      minorTickWidth: 0,
      tickLength: 50,
      tickWidth: 5,
      tickColor: 'white',
      zIndex: 6,
      stops: [
        [0, '#fff'],
        [0.101, '#0f0'],
        [0.201, '#2d0'],
        [0.301, '#4b0'],
        [0.401, '#690'],
        [0.501, '#870'],
        [0.601, '#a50'],
        [0.701, '#c30'],
        [0.801, '#e10'],
        [0.901, '#f03'],
        [1, '#f06']
      ]
    }, {
      linkedTo: 0,
      pane: 1,
      lineWidth: 5,
      lineColor: 'white',
      tickPositions: [],
      zIndex: 6
    }],
    
    series: [{
      animation: false,
      dataLabels: {
        enabled: false
      },
      borderWidth: 0,
      color: Highcharts.getOptions().colors[0],
      radius: '100%',
      innerRadius: '80%',
      data: data
    }]
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/highcharts-more.js"></script>
<script src="https://code.highcharts.com/modules/solid-gauge.js"></script>

<div id="container" style="height: 300px;">
</div>

老问题了,希望下面的demo对新手有所帮助:

Demo