Google gauge - how to remove comma from 1,000.00 | ThingSpeak Plugins | 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
Google gauge - how to remove comma from 1,000.00
No permission to create posts
February 9, 2017
4:18 am
Avatar
mazo
New Member
Members
Forum Posts: 3
Member Since:
February 9, 2017
sp_UserOfflineSmall Offline

Hi,

i would like to display pressure value in format: 1029.61 but the plugin returns like 1,029.61. Please if anybody can help me.

 

Press - gauge

 

Code:

 

<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 = xxxxxxx;
// set your channel's read api key here if necessary
var api_key = 'xxxxxxx';
// maximum value for the gauge
var max_gauge_value = 1060;
// name of the gauge
var gauge_name = 'P [mBar]';

// 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_name);
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.field3;

// if there is a data point display it
if (p) {
//p = Math.round((p / max_gauge_value) * 1023);
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, min: 960, max: 1060,
majorTicks: [960, 980, 1000, 1020, 1040, 1060], minorTicks: 10,

greenFrom: 995,
greenTo: 1030,
greenColor: "#00e600"
};

loadData();

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

</script>

 

February 10, 2017
11:20 am
Avatar
Vinod

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

I think this is because of the locale of the browser. 

Change this line

google.load('visualization', '1', {packages:['gauge']});

to

google.load('visualization', '1', {packages:['gauge'],'language': 'en'});

Also, please refer to this page:

https://developers.google.com/chart/interactive/docs/reference#formatters

specifically the 'pattern' section of the 'NumberFormat' option.

February 11, 2017
11:56 am
Avatar
mazo
New Member
Members
Forum Posts: 3
Member Since:
February 9, 2017
sp_UserOfflineSmall Offline

Hi Vinod,

 

thank you for your help, but it seems something more have to be as i did as you suggested and the comma is still there.

 

BR,

February 15, 2017
8:21 pm
Avatar
Vinod

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

Hi,

Assuming you start from the default gauge, modify the displayData method like this:

// display the data
 function displayData(point) {
 var formatter = new google.visualization.NumberFormat({groupingSymbol:'',decimalSymbol:'.',fractionDigits:'2'}); 
 data.setValue(0, 0, gauge_name);
 data.setValue(0, 1, point);
 formatter.format(data,1);
 chart.draw(data, options);
 }

I believe this should do what you need. If not, please post what you tried and screenshot of what you see.

February 17, 2017
3:59 pm
Avatar
mazo
New Member
Members
Forum Posts: 3
Member Since:
February 9, 2017
sp_UserOfflineSmall Offline

Hi, that did the trick! Cool Thank you very very much!!

BR

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online:
21 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:

BarryMaync, ThomasRougs, DonaldGen, prince, JrGordon, Elamsweems

Administrators: Hans: 387, lee: 457