javascript - 仪表图,如何减小系列宽度?

标签 javascript highcharts gauge

我尝试使用 Highcharts 创建仪表图表。我需要减小系列的宽度,但不幸的是我没有找到如何使用 highcharts 来实现这一点。

这是我想要的输出:

enter image description here

我制作了这个仪表:

Highcharts.chart('container', {

  chart: {
    type: 'solidgauge',
    height: '65%',
    plotBackgroundColor: null,
    plotBackgroundImage: null,
    plotBorderWidth: 0,
    plotShadow: false,
  },

  title: {
    text: '',
    style: {
      fontSize: '24px'
    }
  },

  tooltip: {
    borderWidth: 0,
    color: 'black',
    backgroundColor: 'none',
    shadow: false,
    style: {
      fontSize: '13px'
    },
    align: 'center',
    useHTML: true,
    pointFormat: '<div style="font-size:2em; font-weight: bold;">{point.y}%</div><br><div style="text-align: center;">{series.name}</div>',
    positioner: function(labelWidth) {
      return {
        x: (this.chart.chartWidth - labelWidth) / 2,
        y: (this.chart.plotHeight / 2) - 22
      };
    }
  },

  pane: {
    startAngle: 0,
    endAngle: 360,
    background: [{ 
      outerRadius: '87%',
      innerRadius: '63%',
      backgroundColor: Highcharts.Color(Highcharts.getOptions().colors[1])
        .setOpacity(0.3)
        .get(),
      borderWidth: 0
    }]
  },

  yAxis: {
    min: 0,
    max: 100,
    lineWidth: 0,
    tickPositions: []
  },

  plotOptions: {
    solidgauge: {
      dataLabels: {
        enabled: false
      },
      rounded: true
    }
  },

  series: [{
    name: 'Label',
    data: [{
      color: 'orange',
      radius: '87%',
      innerRadius: '63%',
      y: 64
    }]
  }]
});

(function(H) {
  H.wrap(H.Tooltip.prototype, 'hide', () => {});
}(Highcharts));

var obj = document.getElementById('container')
var chart = Highcharts.charts[obj.getAttribute('data-highcharts-chart')];
var tooltipPoint = chart.series[0].points[0];
chart.tooltip.refresh(tooltipPoint);
#container {
  margin: 0 auto;
  max-width: 400px;
  min-width: 380px;
}

.highcharts-credits {
  display: none;
}
<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"></div>

但是正如你所看到的,我的系列的宽度太大了。有办法减少这个宽度吗?

最佳答案

您可以通过增加pane.background.innerRadiusseries.data.innerRadius来实现它。

代码:

  pane: {
    startAngle: 0,
    endAngle: 360,
    background: [{
      outerRadius: '87%',
      innerRadius: '80%',
      backgroundColor: Highcharts.Color(Highcharts.getOptions().colors[1])
        .setOpacity(0.3)
        .get(),
      borderWidth: 0
    }]
  }

  ...

  series: [{
    name: 'Label',
    data: [{
      color: 'orange',
      radius: '87%',
      innerRadius: '80%',
      y: 64
    }]
  }]

演示:

API引用:

关于javascript - 仪表图,如何减小系列宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56078058/

相关文章:

javascript - MSSQL 上 Sequelize.org 的批量更新

javascript - Highcharts 图表在 zoomType : 'x' area range zoom? 上变为空白

javascript - SVG 路径有奇怪的圆 Angular block

javascript - HIghcharts 衡量不需要的白色边框

javascript - 索引.js :1 Uncaught SyntaxError: Unexpected token <

javascript检查css是否显示div

javascript - Highcharts:是否可以显示类似于饼图图例的旭日图例?

javascript - 如何使用 D3.js 或 C3.js 自定义 Gauge 指针?

Android 如何在速度变化时旋转指针?

javascript - (window).load 预加载站点并提供中止选项