<!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 google-visua...@googlegroups.com.
To unsubscribe from this group, send email to google-visualizati...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-visualization-api?hl=en.
thanks so much roni for getting me started! here is a sample
from .csv.:
"H","DESCRIPTION","TRANSFER LIMIT IN","TRANSFER LIMIT OUT","SCHEDULED
"D","Additional Capacity Available from OP 4 Actions:","0"
CONTRACT"
"H","(MW)","(MW)","(MW)"
"G","7. Interchange Summary"
"D","NYISO AC Ties",-300,1200,286
"D","NYISO NNC",-200,200,200
"D","NYISO CSC",-346,330,330
"D","NB",-800,550,-119
"D","Phase 2",-2000,1200,-1424
"D","Highgate",-218,0,-218
with your script and correct .csv link, my page is not rendering. I'm
guessing it has to do with this section?:
query.setQuery('select dept, sum(salary) group by dept');
paul
On Dec 8, 3:14 am, Roni Biran <roni.bi...@gmail.com> wrote:
> 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....
> ...
>
> read more »
"D","Additional Capacity Available from OP 4 Actions:","0"
"H","DESCRIPTION","TRANSFER LIMIT IN","TRANSFER LIMIT OUT","SCHEDULED
CONTRACT"
"H","(MW)","(MW)","(MW)"
"G","7. Interchange Summary"
"D","NYISO AC Ties",-300,1200,286
"D","NYISO NNC",-200,200,200
"D","NYISO CSC",-346,330,330
"D","NB",-800,550,-119
"D","Phase 2",-2000,1200,-1424
"D","Highgate",-218,0,-218
I have edited this section of your script to reflect data
(above)...getting blank page.
query.setQuery('select SCHEDULED CONTRACT, sum(MW) group by SCHEDULED
CONTRACT');
thanks in advance for help! paul
On Dec 8, 3:14 am, Roni Biran <roni.bi...@gmail.com> wrote:
> 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....
> ...
>
> read more »
But this is a correct file path. This is what the .csv looks like when
opened in browser into spreadsheet (gnumeric linux) from file path:
H (MW) (MW) (MW)
G 7. Interchange Summary
D NYISO AC Ties -300 1200 286
D NYISO NNC -200 200 200
D NYISO CSC -346 330 330
D NB -800 550 -119
D Phase 2 -2000 1200 -1424
thanks for suggestions.
query.setQuery('select Phase 2, sum(MW) group by Phase 2');
> ...
>
> read more »
> ...
>
> read more »
I put the.csv in Google Spreadsheets to show you the
data...ultimately, I need to retrieve the updated .csv daily,
automatically, through a cron job. The output of the data will be
stored in MySQL. Will all this be possible doing this with
Spreadsheets, as opposed to JSON, etc?
Thanks again for support. Paul
On Dec 8, 2:13 pm, Roni Biran <roni.bi...@gmail.com> wrote:
> Hi Paul and sorry for the delay,
>
> Your script should look like this:
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml">
> <head>
> <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
> <title>
> Google Visualization API Sample
> </title>
> <script type="text/javascript" src="http://www.google.com/jsapi"></
> script>
> <script type="text/javascript">
> google.load('visualization', '1', {packages: ['corechart']});
> </script>
> <script type="text/javascript">
> var visualization;
>
> function drawVisualization() {
> var query = new google.visualization.Query(
> 'https://docs.google.com/spreadsheet/tq?key=0Aha5Qc1venTTdEVOOGhZRUlvM...
> ');
>
> query.send(handleQueryResponse);
> }
>
> function handleQueryResponse(response) {
> if (response.isError()) {
> alert('Error in query: ' + response.getMessage() + ' ' + response.
> getDetailedMessage());
> return;
> }
>
> var data = response.getDataTable();
> visualization = new google.visualization.ColumnChart(document.
> getElementById('visualization'));
> visualization.draw(data, null);
> }
>
> google.setOnLoadCallback(drawVisualization);
> </script>
> </head>
> <body style="font-family: Arial;border: 0 none;">
> <div id="visualization" style="height: 400px; width: 400px;"></div>
> </body>
> </html>
>
> Good luck,
>
>
>
>
>
>
>
> On Thu, Dec 8, 2011 at 6:35 PM, Roni Biran <roni.bi...@gmail.com> wrote:
> > Hi Paul,
>
> > I will look at it in an hour or so.
>
> > On 8 בדצמ 2011, at 18:29, paulmo <paul.moll...@gmail.com> wrote:
>
> > here is link to .csv data Roni (google spreadsheet). thanks in advance
> > for helping with query.
>
> >https://docs.google.com/spreadsheet/pub?key=0Aha5Qc1venTTdEVOOGhZRUlv...
> ...
>
> read more »
> ...
>
> read more »