use same chart on multiple places for gauge chart - Javascript highcharts

Javascript examples for highcharts:Gauge Chart

Description

use same chart on multiple places for gauge chart

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>Highcharts Demo</title> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <style id="compiled-css" type="text/css">

#container {/*w  w w  .j ava 2  s  .  c  o m*/
   min-width: 310px;
   max-width: 800px;
   height: 400px;
   margin: 0 auto
}


      </style> 
   </head> 
   <body> 
      <script src="https://code.highcharts.com/highcharts.js"></script> 
      <script src="https://code.highcharts.com/highcharts-more.js"></script> 
      <div class="gaugeContainer"></div> 
      <div class="gaugeContainer"></div> 
      <script type="text/javascript">
var options = {
    series: [{
        type: 'gauge'
    }],
    pane: {
        startAngle: -150,
        endAngle: 150
    },
    yAxis: {
        min: 0,
        max: 200
    }
}
var containers = document.getElementsByClassName('gaugeContainer');
for (var i = 0; i < containers.length; i++) {
    Highcharts.chart(containers[i], options);
}
function setChartsData(data) {
    Highcharts.charts.forEach(function(chart) {
        if (chart && chart.renderTo.classList.contains("gaugeContainer")) {
            chart.series[0].setData(data.slice());
        }
    });
}
setChartsData([32]);
setTimeout(function() {
    setChartsData([120]);
}, 1500)

      </script>  
   </body>
</html>

Related Tutorials