Solid gauge

author(s): Torstein Hønsi

by Black Label

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>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>
<script src="https://code.highcharts.com/modules/accessibility.js"></script>

<figure class="highcharts-figure">
    <div id="container-speed" class="chart-container"></div>
    
</figure>

JavaScript

var allowChartUpdate = true;
var gaugeOptions = {
  chart: {
    type: 'solidgauge',
    events: {
      render: function() {
        var tickLength = this.pane[0].group.getBBox().width / 4

        if (allowChartUpdate) {
          allowChartUpdate = false;

          this.yAxis[0].update({
            tickLength: tickLength
          });

          allowChartUpdate = true;
        }
      }
    }
  },

  title: null,

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

  exporting: {
    enabled: false
  },

  tooltip: {
    enabled: false
  },

  // the value axis
  yAxis: {
    stops: [
      [0.1, '#55BF3B'], // green
      [0.5, '#DDDF0D'], // yellow
      [0.9, '#DF5353'] // red
    ],


    lineWidth: 2,
    tickWidth: 10,
    tickInterval: 10,
    lineColor: '#fff',

    minorTickInterval: null,
    labels: {
      enabled: false
    },
    minorTickPosition: 'inside',
    tickPosition: 'inside',
    tickPixelInterval: 10,
    tickLength: '50',
    tickColor: '#fff',
    zIndex: 6,

    minorTickWidth: 0,
  },

  plotOptions: {
    solidgauge: {
      dataLabels: {
        enabled: false
      },
      rounded: false
    },
    gauge: {
      dial: {
        radius: '40',
        backgroundColor: '#1d96e0',
        baseWidth: 20,
        topWidth: 1,
        baseLength: '5%', // of radius
        rearLength: '0%'
      },
      pivot: {
        radius: '10',
        backgroundColor: '#1d96e0'
      }
    },
    series: {
      dataLabels: {
        enabled: true
      }
    }
  },
};

// The speed gauge

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

  credits: {
    enabled: false
  },

  series: [{
      name:...