高图仪表图尺寸

时间:2020-06-22 13:38:50

标签: javascript charts highcharts

我一直在尝试缩小量规。我通过将innerRadius设置为90%取得了一些成功,但是我无法更改绿色部分的大小。它总是更大。我也尝试过与“ outerRadius”一起玩,但是到目前为止还算幸运。

var gaugeOptions = {

  chart: {
    type: 'solidgauge'
  },

  title: null,

  pane: {
    center: ['30%', '85%'],
    size: '150%',
    startAngle: -90,
    endAngle: 90,
    background: {
      backgroundColor: Highcharts.defaultOptions.legend.backgroundColor || '#EEE',
      innerRadius: '110%',
      outerRadius: '85%',
      shape: 'arc'
    }
  },

  tooltip: {
    enabled: false
  },

  // the value axis
  yAxis: {
    stops: [
      [0.1, '#55BF3B'], // green
      [0.5, '#DDDF0D'], // yellow
      [0.9, '#DF5353'] // red
    ],
    lineWidth: 0,
    minorTickInterval: null,
    tickAmount: 2,
    title: {
      y: -70
    },
    labels: {
      y: 16
    }
  },

  plotOptions: {
    solidgauge: {
      dataLabels: {
        y: 5,
        borderWidth: 0,
        useHTML: true
      }
    }
  }
};

// The speed gauge
var chartSpeed = Highcharts.chart('container-speed', Highcharts.merge(gaugeOptions, {
  yAxis: {
    min: 0,
    max: 100,
    title: {
      text: ''
    }
  },

  credits: {
    enabled: false
  },

  series: [{
    name: 'Speed',
    data: [20],
    dataLabels: {
      format: '<div style="text-align:center">' +
        '<span style="font-size:25px">{y}</span><br/>' +
        '<span style="font-size:12px;opacity:0.4">km/h</span>' +
        '</div>'
    }
  }]

}));

这里是fiddle。我基本上是在尝试使绿色与灰色匹配。

2 个答案:

答案 0 :(得分:2)

可以通过在radius中添加属性innerRadiusseries.data来设置绿色部分的大小。 您的情况应该是:

series: [{
  name: 'Speed',
  data: [{
    y: 20,
    radius: 90,
    innerRadius: 105
  }],
  dataLabels: {...}
}]

更多信息here

答案 1 :(得分:0)

您还可以在系列级别上设置radiusinnerRadius属性:

    series: [{
        radius: 90,
        innerRadius: 105,
        ...
    }]

实时演示: https://jsfiddle.net/BlackLabel/fwumc7db/

API参考:

https://api.highcharts.com/highcharts/series.solidgauge.innerRadius

https://api.highcharts.com/highcharts/series.solidgauge.radius