Google Gauge Chart - Add Text Label for each gauge section

7.2k Views Asked by At

I am trying to use Google gauge charts in my page. Now I want to add text in the chart for each section or colors. Can I do that inside the chart. I tried doing some html modification but with no help.

Trying from this link -https://developers.google.com/chart/interactive/docs/gallery/gauge enter image description here

So for example, I would like to add text1 for white color and so on.

1

There are 1 best solutions below

0
WhiteHat On

use the majorTicks config option to provide labels for the major ticks

see following working snippet...

google.charts.load('current', {
  callback: function () {
    var container = document.getElementById('chart_div');
    var chart = new google.visualization.Gauge(container);

    var data = google.visualization.arrayToDataTable([
      ['Label', 'Value'],
      ['Memory', 80],
      ['CPU', 55],
      ['Network', 68]
    ]);

    var options = {
      width: 600, height: 200,
      redFrom: 90, redTo: 100,
      yellowFrom:75, yellowTo: 90,
      majorTicks: ['A', 'B', 'C', 'D', 'E'],
      minorTicks: 3
    };

    chart.draw(data, options);
  },
  packages: ['gauge']
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>