测量图表与颜色的步骤

时间:2016-10-20 06:14:16

标签: javascript d3.js charts highcharts donut-chart

enter image description here

如何使用highcarts实现这一目标?累了使用停止:[...]但它不会像上面的图像一样工作。

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>'
            }
        }]

2 个答案:

答案 0 :(得分:4)

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

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

&#13;
&#13;
$(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
    }]
  });
});
&#13;
<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>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

即使这是一个老问题,我希望下面的演示对新用户有所帮助:

Demo

round slider - gauge chart with step of gradient colors