Adding units to Google Gauge: ie. %, hPa, °C | ThingSpeak Apps | Forum

Avatar

Please consider registering
Guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
Adding units to Google Gauge: ie. %, hPa, °C
No permission to create posts
September 22, 2016
12:47 am
Avatar
clag
New Member
Members
Forum Posts: 1
Member Since:
September 22, 2016
sp_UserOfflineSmall Offline

I'd like to be able to add units to the bottom value on google gauges. I have tried:

var formatter = new google.visualization.NumberFormat({pattern: "#'%'"});

but cannot get it to work.

also:

var formatter = new google.visualization.NumberFormat(
{suffix: '%',pattern:'#'}
);
formatter.format(data,1);

 

Could anyone help me?

September 22, 2016
5:15 pm
Avatar
Vinod

MathWorks
Members
Forum Posts: 200
Member Since:
May 1, 2016
sp_UserOfflineSmall Offline

I have this code that puts the units on a gauge. Perhaps you can modify it for your use case:

 

<script type='text/javascript' src='https://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 = MYCHANNELNUM;
// set your channel's read api key here if necessary
var api_key = 'MYCHANNELKEY';
// maximum value for the gauge
var max_gauge_value = 100;
// maximum value for the gauge
var gauge_text = '°C';

// 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_text);
data.setValue(0, 1, point);
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.field1;

// if there is a data point display it
if (p) {
p = (Math.round((p / max_gauge_value) * 1000) / 10);
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 = {min: 25, width: 240, height: 240, redFrom: 90, redTo: 100, yellowFrom:75, yellowTo: 90, minorTicks: 5};

loadData();

// load new data every 15 seconds
setInterval('loadData()', 15000);
}

</script>

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online:
15 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 261

Vinod: 196

piajola: 85

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

Newest Members:

celinabw2, FitoSprayscroma, LunnonGor, lancevl16, bernicenk60, veronicadq18

Administrators: Hans: 387, lee: 457