Solid gauge

author(s): Torstein Hønsi

by sundaramkumar

HTML

<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-speed" class="chart-container"></div>

JavaScript

var chartSpeed = Highcharts.chart('container-speed', {
  chart: {
    type: 'solidgauge',
    events: {
      render: function() {
        const chart = this,
          diameter = this.pane[0].center[2],
          dialWidth = diameter / 2 * 0.4;


        if (chart.diameter !== this.pane[0].center[2]) {
          chart.diameter = this.pane[0].center[2];
          chart.series[0].update({
            dial: {
              path: [
                ['M', diameter / 2 * 0.6, 0],
                ['l', dialWidth+5, 0],
                ['l', 0, 0],
                ['l', 0, 7],
                ['l', -dialWidth-5, 0]
              ],
              backgroundColor: '#2b2b2baa'
            },
          })
        }
      }
    }
  },

  title: null,
  legend: {
    enabled: true,
    floating: true
  },
  pane: {
    startAngle: -90,
    endAngle: 90,
    background: {
      backgroundColor: Highcharts.defaultOptions.legend.backgroundColor || '#EEE',
      innerRadius: '60%',
      outerRadius: '100%',
      shape: 'arc'
    }
  },

  tooltip: {
    enabled: false
  },

  // the value axis
  yAxis: {
    min: 0,
    max: 100,
    labels: {
      enabled: false
    },
    gridLineColor: 'transparent',
    lineColor: 'transparent',
    minorTickLength: 0,
    tickColor: Highcharts.defaultOptions.legend.backgroundColor,
    stops: [
      [0.1, '#729c49'], // green
      [0.5, '#e2cf40'], // yellow
      [0.9, '#e46c00'] // red
    ],
    plotBands: [{
      from: 0,
      to: 70,
      color: "#729c49",
      innerRadius: "60%",
      label: {
        text: ''
      },
    }, {
      from: 70,
      to: 90,
      color: "#e2cf40",
      innerRadius: "60%",
      label: {
        text: ''
      }
    }, {
      from: 90,
      to: 100,
      color: "#e46c00",
      innerRadius: "60%",
      label: {
        text: ''
      }
    }]
  },

  plotOptions: {
    series: {
      dataLabels: {
        y: 5,
        borderWidth: 0,
        useHTML: true
      }
    },
    guage: {
    ...