Trying to build a graph from a CSV data. But not showing any graph.

76 views
Skip to first unread message

Sekhar Krishna Kondisetty

unread,
Nov 28, 2015, 7:58:36 PM11/28/15
to Google Visualization API
Hi All - 

I am new to Google Development and want to build a dashboard for my business using Google Charts. Hence i started exploring this. As part of this, i am trying to build a code to generate a graph using a CSV. For this i have installed IIS on my laptop and find the details below.

IIS Location: C:\inetpub\wwwroot
CSV Location: C:\inetput\wwwroot\MySite
CSV Details: It is a simple CSV and here are those details.

  
1,300
2,400
3,699
4,876


Code: 


<html>
  <head>
    <!--Load the AJAX API-->
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
      // Load the Visualization API and the piechart package.
      google.load('visualization', '1.0', {'packages':['corechart']});

      // Set a callback to run when the Google Visualization API is loaded.
   google.setOnLoadCallback(initialize);

      // Callback that creates and populates a data table,
      // instantiates the pie chart, passes in the data and
      // draws it.


function initialize() {
  var opts = {sendMethod: 'auto'};
  // Replace the data source URL on next line with your data source URL.
  var query = new google.visualization.Query('http://localhost/MySite/data.csv');

  // Optional request to return only column C and the sum of column B, grouped by C members.
  query.setQuery('select A, B');

  // Send the query with a callback function.

  query.send(handleQueryResponse);
}

function handleQueryResponse(response) {
  if (response.isError()) {
    alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
    return;
  }
  var data = response.getDataTable();
  var chart = new google.visualization.BarChart(document.getElementById('chart_div'));
  chart.draw(data, {width: 400, height: 240, is3D: true});
}

    </script>
  </head>

  <body>
    <!--Div that will hold the pie chart-->
    <div id="chart_div"></div>
  </body>
</html>


Could you please help me in understanding the issue? This is not generating any output. 


Thanks. 

Sergey Grabkovsky

unread,
Nov 30, 2015, 10:03:42 AM11/30/15
to Google Visualization API
Hi Sekhar,

The Query is primarily for loading JSON data. It can load CSV, but this functionality is currently undocumented. There was a thread a while ago where I explained how to use Query with a CSV file. You may find it here.

--
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 google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-visualization-api/be176b4b-158a-4494-9b1c-69ae3fef058c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--

unnamed.gif

Sergey Grabkovsky

Software Engineer

Google, Inc

gra...@google.com

Sekhar Krishna Kondisetty

unread,
Dec 4, 2015, 8:56:03 PM12/4/15
to Google Visualization API
Hi Sergey,

Thanks for your response. Now it is working after following instructions mentioned in the link.

Regards,
Ratna Sekhar K.,
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages