Your JSON isn't in the correct format for the arrayToDataTable method to
use. Try this:
var rows = [['Label', 'Value']];
json = JSON.parse(json);
rows.push(['TempOut', json.TempOut]);
rows.push(['FeelsLike', json.FeelsLike]);
rows.push(['HumidityOut', json.HumidityOut]);
rows.push(['WindAvg', json.WindAvg]);
rows.push(['WindGust', json.WindGust]);
rows.push(['Rain', json.Rain]);
rows.push(['AbsPressure', json.AbsPressure]);
var data = google.visualization.arrayToDataTable(rows);
On Wednesday, January 8, 2014 1:38:17 PM UTC-5, Hystrix wrote:
>
> I have weather data on my website in the following JSON format, in a file
> called JSON.txt:
>
> {
> "TempOut": 10.1,
> "FeelsLike": 8.2,
> "HumidityOut": 93,
> "WindAvg": 2,
> "WindGust": 4,
> "Rain": 9.3,
> "AbsPressure": 998.6
> }
>
> I have been trying for days trying to get a simple webpage to display
> gauges for each of these values. My code looks like this:
>
> <html xmlns="http://www.w3.org/1999/xhtml">
> <head>
> <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
> <title>
> Current Weather
> </title>
> <script type="text/javascript" src="//www.google.com/jsapi"></script>
> <script type="text/javascript">
> google.load('visualization', '1', {packages: ['gauge']});
> </script>
> <script type="text/javascript">
>
> function drawChart() {
> var data;
> var options = {
> width: 400,
> height: 120,
> };
>
> var chart = new google.visualization.Gauge(document.getElementById(
> 'chart_div'));
>
> function refreshData () {
> var json = $.ajax({
> url: 'http://mywebsite/weather/JSON.txt',
> dataType: 'json',
> async: false
> }).responseText;
>
> data = google.visualization.arrayToDataTable(json);
>
> chart.draw(data, options);
> }
>
> refreshData();
> setInterval(refreshData, 1000);
> }
> </script>
> </head>
> <body>
> <div id="chart_div"></div>
> </body>
> </html>
>
> I would be really grateful if someone could point me in the right
> direction. No matter what I try in the Google Code Playground, I cant even
> get a single gauge to display.
>
> Many thanks.
>
--
You received this message because you are subscribed to the Google Groups
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/groups/opt_out.