My Google Gauge is showing blank on thing speak

조회 수: 57 (최근 30일)
Aniket Manjare
Aniket Manjare 2021년 1월 1일
댓글: Aniket Manjare 2021년 1월 12일
this is the JavaScript code i have written on under Thingspeak plugin > Google Guage
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js'></script>
<script type='text/javascript' src='https://www.google.com/jsapi'></script>
<script type='text/javascript'>
// set your channel id here
var channel_id = 1264170;
// set your channel's read api key here
var api_key = '8YD9SX9ZU17OEQ5N';
// list of name off the gauge and value
var value_names = ['','ON','BLOCK','TAPE'];
var gauge_names = ['OFF','Normal','Abnormal', 'Alert!'];
// global variables
var chart, charts, data;
// load the google gauge visualization
google.load('visualization', '1', {packages:['gauge']});
google.setOnLoadCallback(initChart);
// display the data
function displayData(point) {
data.setValue(0, 0, gauge_names[point]);
data.setValue(0, 1, point);
data.setFormattedValue(0, 1, value_names[point]); //Formatting font and font size is not possible in gauge chart
chart.draw(data, options);
}
// load the data
function loadData() {
// variable for the data point
var p;
// get the data from thingspeak
$.getJSON('https://api.thingspeak.com/channels/' + channel_id + '/feed/last.json?api_key=' + api_key, function(data) {
// get the data point
p = data.field3;
// if there is a data point display it
if (p) {
displayData(p);
}
});
}
// initialize the chart
function initChart() {
data = new google.visualization.DataTable();
data.addColumn('string', 'Label');
data.addColumn('number', 'Value');
data.addRows(1);
chart = new google.visualization.Gauge(document.getElementById('gauge_div'));
options = {width: 240, height: 240, max: 3, redFrom: 1.5, redTo: 3, greenFrom:0.5, greenTo: 1.5, minorTicks: 0, majorTicks: ["Off","","","Bad"]};
loadData();
// load new data every 1 second
setInterval('loadData()', 1000);
}
</script>

답변 (1개)

Vinod
Vinod 2021년 1월 1일
Why not use the gauge widget? Any particular reason you want the Google gauge, specifically?
  댓글 수: 4
Christopher Stapels
Christopher Stapels 2021년 1월 3일
@Aniket In your channel view press the "add Widgets" button near the top of the channel view.
Select the Gauge widget. You can see more help in the documentation for widgets.
Aniket Manjare
Aniket Manjare 2021년 1월 12일
Hello, i am using the guage provided by the Thingspeak only. i have made some changes in the code , the problem is when i am use thr default code i can see the guage and when i am using the the above code its not appearing , can you please tell why i am getting this error.

댓글을 달려면 로그인하십시오.

커뮤니티

더 많은 답변 보기:  ThingSpeak 커뮤니티

카테고리

Help CenterFile Exchange에서 Web Services에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by