Hi dreamER, thank you for your respond!
I copied your code with my token and device id, but didn’t work. So I did try to adapt my code to yours, making some changes.
This is my whole .js code
var accessToken = "xxx";
var deviceID = "xxx"
var url_temp = "https://api.particle.io/v1/devices/" + deviceID + "/Temperatura";
var layout = { width: 300, height: 300, margin: { t: 0, b: 0 } };
//TEMPERATURA
function callback_temp(data, status){
if (status == "success") {
temp = JSON.parse(data.result);
plot(temp.temperature_c);
}
else {
alert("There was a problem");
}
}
function getReading_temp(){
$.get(url_temp, {access_token: accessToken}, callback_temp);
}
// GOOGLE GAUGE
google.charts.load('current', {'packages':['gauge']});
google.charts.setOnLoadCallback(temperatura);
//MEDIDOR DE TEMPERATURA
function temperatura() {
var data = google.visualization.arrayToDataTable([
['Label', 'Value'],
['Temperatura', 0],
]);
var options = {
width: 250, height: 250,
yellowFrom:30, yellowTo: 40,
redFrom: 40, redTo: 50,
minorTicks: 5,
min:0,
max:50,
};
var chart = new google.visualization.Gauge(document.getElementById('chart_temp'));
setInterval(function()
{
getReading_temp();
chart.draw(data, options);
data.setValue(0, 1, temp);
}, 1000);
}
//----------------------------high-charts graph
var gaugeOptions = {
chart: {
type: 'solidgauge'
},
title: null,
pane: {
center: ['50%', '85%'],
size: '150%',
startAngle: -90,
endAngle: 90,
background: {
backgroundColor:
Highcharts.defaultOptions.legend.backgroundColor || '#2B1B17',
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: 0,
tickWidth: 0,
minorTickInterval: null,
tickAmount: 2,
title: {
y: -70
},
labels: {
y: 16
}
},
plotOptions: {
solidgauge: {
dataLabels: {
y: 5,
borderWidth: 0,
useHTML: true
}
}
}
};
// The speed gauge
var chartSpeed = Highcharts.chart('chart-temp', Highcharts.merge(gaugeOptions, {
yAxis: {
min: 0,
max: 60,
title: {
text: 'ºC'
}
},
credits: {
enabled: false
},
series: [{
name: 'Speed',
data: [0],
dataLabels: {
format:
'<div style="text-align:center">' +
'<span style="font-size:80px">{y}</span><br/>' + //TAMAÑO NUMERO DE ABAJO
'<span style="font-size:12px;opacity:0.4">ºC</span>' + //tamaño unidades
'</div>'
},
tooltip: {
valueSuffix:'TEMP'
}
}]
}));
// Updating the graph
setInterval(function () {
var point,
newVal,
inc;
if (chartSpeed) {
point = chartSpeed.series[0].points[0];
inc = Math.round((Math.random() - 0.5) * 100);
newVal = point.y + inc;
if (newVal < 0 || newVal > 200) {
newVal = point.y - inc;
}
point.update(temp);
}
}, 2000);
//----------------------------PLOTLY GRAPH------------------------
function plot(temp){
var data = [
{
domain: { x: [0, 1], y: [0, 1] },
value : temp,
title: { text: "Temp" },
type: "indicator",
mode: "gauge+number"
}
];
Plotly.newPlot('prueba', data, layout);
}
setInterval(function(){
getReading_temp();
}, 1000);
I did change your variable res for mine, temp
function plot(temp){
var data = [
{
domain: { x: [0, 1], y: [0, 1] },
value : temp,
title: { text: "Temp" },
type: "indicator",
mode: "gauge+number"
}
];
This is how it is display
ps.
I change:
var temp = JSON.parse(data.result);
to:
temp = JSON.parse(data.result);
Because leaving the var temp will affect the other two graphs, displaying them like this:
I really don’t know why this happened.
Thank you again for your help.