- Joined
- Jul 16, 2023
- Messages
- 3
- Reaction score
- 0
Hi, I'd like to understand how to edit the code below, in order to have a single static image,
with 2,3 or 4 gauges, each one with different scale, data, colors, everything.
The code come from here: https://developers.google.com/chart/interactive/docs/gallery/gauge
My attempt to edit:
with 2,3 or 4 gauges, each one with different scale, data, colors, everything.
The code come from here: https://developers.google.com/chart/interactive/docs/gallery/gauge
JavaScript:
<html>
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['gauge']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Label', 'Value'],
['Memory', 80],
['CPU', 55],
['Network', 68]
]);
var options = {
width: 400, height: 120,
redFrom: 90, redTo: 100,
yellowFrom:75, yellowTo: 90,
minorTicks: 5
};
var chart = new google.visualization.Gauge(document.getElementById('chart_div'));
chart.draw(data, options);
setInterval(function() {
data.setValue(0, 1, 40 + Math.round(60 * Math.random()));
chart.draw(data, options);
}, 13000);
setInterval(function() {
data.setValue(1, 1, 40 + Math.round(60 * Math.random()));
chart.draw(data, options);
}, 5000);
setInterval(function() {
data.setValue(2, 1, 60 + Math.round(20 * Math.random()));
chart.draw(data, options);
}, 26000);
}
</script>
</head>
<body>
<div id="chart_div" style="width: 400px; height: 120px;"></div>
</body>
</html>
My attempt to edit:
JavaScript:
<html>
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['gauge']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Label', 'Value'],
['Avg QP', 16.82],
['Rate', 51],
['Remux', 17.51],
['Speed', 3.89]
]);
var options = {
width: 720, height: 360, min: 15, max: 26,
redFrom: 25, redTo: 26,
yellowFrom: 23, yellowTo: 25,
greenFrom: 16, greenTo: 23,
minorTicks: 10, majorTicks: ['15','16','17','18','19','20','21','22','23','24','25','26']
};
var chart = new google.visualization.Gauge(document.getElementById('chart_div'));
chart.draw(data, options);
setInterval(function() {
data.setValue('Avg QP');
chart.draw(data, options);
});
setInterval(function() {
data.setValue('Rate');
chart.draw(data, options);
});
setInterval(function() {
data.setValue('Remux');
chart.draw(data, options);
});
setInterval(function() {
data.setValue('Speed');
chart.draw(data, options);
});
}
</script>
</head>
<body>
<div id="chart_div" style="width: 800px; height: 240px;"></div>
</body>
</html>