Hi paulmo,
Sadly you did not follow the exact instructions :-(
1. The code you copied is a servlet code (i.e. runs on the server. this is
not a client side JavaScript).
2. Your script should hold a function named "drawChart" that will be called
after the page load is completed (google.setOnLoadCallback). That function
will call another function with the data that will eventually draw the
chart.
3. Your CSV in inaccessible here. Can you send a sample from the CSV
itself. If I were you, I would use the Google spreadsheet as an example.
After saying all that (and assuming that your CSV works), your script
should look something like this:
<script type="text/javascript">
google.load('visualization', '1', {'packages':['corechart']});
google.setOnLoadCallback(drawChart);
function drawChart() {
var query = new google.visualization.Query('csv?url=
http://www.iso-ne.com/sys_ops/csvdocs/morning_report2011-12-07-08-18.csv');
query.setQuery('select dept, sum(salary) group by dept');
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.OrgChart(document.getElementById('csv_div'));
chart.draw(data);
}
</script>
Best of luck,
On Thu, Dec 8, 2011 at 2:55 AM, paulmo <[email protected]> wrote:
> Have implemented according to instructions. CSV contains text and
> numbers. My page is below, but first, if it helps, this is how
> the .csv renders into JSON (but I'm not using JSON in external csv
> file example). Thanks in advance for help.
> [{"C":"C","Morning Report":"Report for 12\/7\/2011"},{"C":"C","Morning
> Report":"Report Generated 12\/07\/2011 13:18:10 GMT"},
> {"C":"H","Morning Report":"DESCRIPTION"},{"C":"H","Morning Report":""},
> {"C":"G","Morning Report":"Report Type"},{"C":"D","Morning
> Report":"Morning Report"},{"C":"H","Morning Report":"DATE","":"TIME"},
> {"C":"H","Morning Report":"","":""},{"C":"G","Morning Report":"1.
> Report Date"},{"C":"D","Morning Report":"Wednesday, Dec 7
> 2011","":"08:18:10 EST"},{"C":"H","Morning
> Report":"DESCRIPTION","":"VALUE"},{"C":"H","Morning
> Report":"","":"(MW)"},{"C":"G","Morning Report":"2. Peak Load"},
> {"C":"D","Morning Report":"Tuesday, Dec 6 2011 hour ending
> 18","":"17755"},{"C":"G","Morning Report":"3. Operable Capacity
> Analysis"},{"C":"D","Morning Report":"A. Capacity Supply Obligation
> (CSO)","":"30957"},{"C":"D","Morning Report":"B. Capacity Additions
> EcoMax Bid > CSO","":"2272"},{"C":"D","Morning Report":"C. Pre-OP4
> Dispatchable Loads","":"0"},{"C":"D","Morning Report":"D. Generation
> Outages and Reductions","":"4474"},{"C":"D","Morning Report":"E.
> Uncommitted Available Generation (non fast start)","":"9070"},
> {"C":"G","Morning Report":"F. Capacity Deliveries: Net Purchases = (-)
> Net Sales = (+)"},{"C":"D","Morning Report":"NYISO AC Ties","":"167"},
> {"C":"D","Morning Report":"NYISO NNC","":"200"},{"C":"D","Morning
> Report":"NYISO CSC","":"330"},{"C":"D","Morning Report":"NB","":"222"},
> {"C":"D","Morning Report":"Phase 2","":"-1225"},{"C":"D","Morning
> Report":"Highgate","":"-218"},{"C":"D","Morning Report":"Net
> Deliveries","":"-524"},{"C":"D","Morning Report":"G. Total Available
> Capacity (A+B+C-D-E-F)","":"20209"},{"C":"D","Morning Report":"H. Peak
> Load Forecast For Hour 18","":"17900"},{"C":"D","Morning Report":"I.
> Total Operating Reserve Requirement","":"1863"},{"C":"D","Morning
> Report":"J. Capacity Required","":"19763"},{"C":"D","Morning
> Report":"K. Surplus = (+) Deficiency = (-) (G - J)","":"446"},
> {"C":"D","Morning Report":"L. Replacement Reserve Requirement","":"0"},
> {"C":"D","Morning Report":"M. Excess Commitment Surplus = (+)
> Deficiency = (-) (K - L)","":"446"},{"C":"G","Morning Report":"4.
> Largest First Contingency"},{"C":"D","Morning
> Report":"____","":"1245"},{"C":"G","Morning Report":"5. Annual
> Maintenance Schedule (A.M.S)"},{"C":"D","Morning Report":"Peak Load
> Exposure","":"20393"},{"C":"G","Morning Report":"6. Reserve Summary"},
> {"C":"D","Morning Report":"Ten Minute Reserve Requirement:","":"1245"},
> {"C":"D","Morning Report":"Ten Minute Reserve Estimate:","":"1245"},
> {"C":"D","Morning Report":"Thirty Minute Reserve
> Requirement:","":"618"},{"C":"D","Morning Report":"Thirty Minute
> Reserve Estimate:","":"1064"},{"C":"D","Morning Report":"Expected ICU
> Operation","":"0"},{"C":"D","Morning Report":"Expected Actions of OP
> 4:","":"0"},{"C":"D","Morning Report":"Additional Capacity Available
> from OP 4 Actions:","":"0"},{"C":"H","Morning
> Report":"DESCRIPTION","":"SCHEDULED CONTRACT"},{"C":"H","Morning
> Report":"(MW)","":"(MW)"},{"C":"G","Morning Report":"7. Interchange
> Summary"},{"C":"D","Morning Report":"NYISO AC Ties","":"167"},
> {"C":"D","Morning Report":"NYISO NNC","":"200"},{"C":"D","Morning
> Report":"NYISO CSC","":"330"},{"C":"D","Morning Report":"NB","":"222"},
> {"C":"D","Morning Report":"Phase 2","":"-1225"},{"C":"D","Morning
> Report":"Highgate","":"-218"},{"C":"H","Morning
> Report":"CITY","":"HIGH TEMP"},{"C":"H","Morning Report":"","":"(F)"},
> {"C":"G","Morning Report":"8. Weather Forecast Summary for the Peak
> Hour"},{"C":"D","Morning Report":"Boston","":"45"},{"C":"D","Morning
> Report":"Hartford","":"46"},{"C":"H","Morning
> Report":"DESCRIPTION","":"VALUE"},{"C":"H","Morning Report":"","":""},
> {"C":"G","Morning Report":"9. SAR Available"},{"C":"D","Morning
> Report":"NYISO","":"Yes"},{"C":"H","Morning
> Report":"DESCRIPTION","":"VALUE"},{"C":"H","Morning
> Report":"","":"(MW)"},{"C":"G","Morning Report":"10. Capacity of Non-
> Commercial Units"},{"C":"D","Morning Report":"Total Available","":"0"},
> {"C":"G","Morning Report":"11. Units Committed to Meet Minimum
> Operating Reserve and Replacement Reserve Requirements"},
> {"C":"D","Morning Report":"0 Units","":"0"},{"C":"H","Morning
> Report":"DESCRIPTION","":"VALUE"},{"C":"H","Morning Report":"","":""},
> {"C":"G","Morning Report":"12. Solar Magnetic Disturbance Activity"},
> {"C":"D","Morning Report":"Forecast:","":""},{"C":"D","Morning
> Report":"Alert:","":""},{"C":"D","Morning Report":"Intensity:","":""},
> {"C":"D","Morning Report":"Observed Activity:","":""},
> {"C":"D","Morning Report":"Actions Taken or Planned by ISO-NE:","":""},
> {"C":"D","Morning Report":"Actions Taken or Planned by Other Control
> Areas:","":""},{"C":"T","Morning Report":"44 Lines"}]
>
>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
> <head>
> <!--Load the AJAX API-->
> <script type="text/javascript" src="https://www.google.com/
> jsapi"></script>
> <script type="text/javascript" src="jquery-1.7.1.min.js"></script>
> <script type="text/javascript">
>
> // Load the Visualization API and the piechart package.
> google.load('visualization', '1', {'packages':['corechart']});
>
> // Set a callback to run when the Google Visualization API is
> loaded.
> google.setOnLoadCallback(drawChart);
>
> query = new google.visualization.Query('csv?url=http://www.iso-ne.com/
> sys_ops/csvdocs/morning_report2011-12-07-08-18.csv');
>
> var chart = new
> google.visualization.OrgChart(document.getElementById('csv_div'));
>
> </script>
> </head>
>
> <body>
>
> <script type="text/javascript">
> public class CsvDataSourceServlet extends DataSourceServlet {
>
> /**
> * Log.
> */
> private static final Log log =
> LogFactory.getLog(CsvDataSourceServlet.class.getName());
>
> /**
> * The name of the parameter that contains the url of the CSV to
> load.
> */
> private static final String URL_PARAM_NAME = "http://www.iso-ne.com/
> sys_ops/csvdocs/morning_report2011-12-07-08-18.csv";
>
> /**
> * Generates the data table.
> * This servlet assumes a special parameter that contains the CSV
> URL from which to load
> * the data.
> */
> @Override
> public DataTable generateDataTable(Query query, HttpServletRequest
> request)
> throws DataSourceException {
> String url = request.getParameter(URL_PARAM_NAME);
> if (StringUtils.isEmpty(url)) {
> log.error("url parameter not provided.");
> throw new DataSourceException(ReasonType.INVALID_REQUEST, "url
> parameter not provided");
> }
>
> Reader reader;
> try {
> reader = new BufferedReader(new InputStreamReader(new
> URL(url).openStream()));
> } catch (MalformedURLException e) {
> log.error("url is malformed: " + url);
> throw new DataSourceException(ReasonType.INVALID_REQUEST, "url
> is malformed: " + url);
> } catch (IOException e) {
> log.error("Couldn't read from url: " + url, e);
> throw new DataSourceException(ReasonType.INVALID_REQUEST,
> "Couldn't read from url: " + url);
> }
> DataTable dataTable = null;
> ULocale requestLocale =
> DataSourceHelper.getLocaleFromRequest(request);
> try {
> // Note: We assume that all the columns in the CSV file are text
> columns. In cases where the
> // column types are known in advance, this behavior can be
> overridden by passing a list of
> // ColumnDescription objects specifying the column types. See
> CsvDataSourceHelper.read() for
> // more details.
> dataTable = CsvDataSourceHelper.read(reader, null, true,
> requestLocale);
> } catch (IOException e) {
> log.error("Couldn't read from url: " + url, e);
> throw new DataSourceException(ReasonType.INVALID_REQUEST,
> "Couldn't read from url: " + url);
> }
> return dataTable;
> }
> }
>
>
> </script>
>
> <!--Div that will hold the pie chart-->
> <div id="csv_div"></div>
>
> </body>
> </html>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Visualization API" group.
> To post to this group, send email to
> [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-visualization-api?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"Google Visualization API" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-visualization-api?hl=en.