Thanks for the link, but I am still lost as to how to implement this information. If I look at a simple example:
If I create a csv file called test.csv that contains the following: Number 1 I then call this function using: http://localhost:8080/myWebApp/csv?url=http://localhost:8080/myWebApp/test.csv I get the following returned: google.visualization.Query.setResponse ({version:'0.6',status:'ok',sig:'1736046499',table:{cols: [{id:'Col0',label:'Number',type:'string',pattern:''}],rows:[{c: [{v:'1'}]}]}}); Can show me the code I need to add so that it returns 1 as a number and not a string? Thanks....George On Dec 1, 1:44 pm, Viz Kid <[email protected]> wrote: > You can find an example usage of this code in its test > file:http://www.google.com/codesearch/p?hl=en#aLJwv4TSmDw/trunk/src/test/j... > > Viz Kid > > > > On Tue, Dec 1, 2009 at 8:11 PM, gman <[email protected]> wrote: > > Viz Kid --- You are definitely on the right track. It looks like the > > package I am using expects to see strings only. This is the output I > > get: > > > google.visualization.Query.setResponse > > ({version:'0.6',status:'ok',sig:'1758220977',table:{cols: > > [{id:'Col0',label:'string',type:'string',pattern:''}, > > {id:'Col1',label:'number',type:'string',pattern:''}],rows:[{c: > > [{v:'Memory'},{v:'80'}]},{c:[{v:'CPU'},{v:'55'}]},{c:[{v:'Network'}, > > {v:'68'}]}]}}); > > > The first cloumn in the csv file is a string and the second is a > > number. This is returning them both as strings. The culprit seems to > > be the CsvDataSourceHelper. I am using the code from the examples, > > specifically CsvDataSourceServlet. In this code is the following > > comments: > > > // 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); > > > So it looks like I need to change the options from the > > CsvDataSourceHelper. From the documentation the fields are defined as: > > > reader - The CSV input Reader from which to read. > > columnDescriptions - The column descriptions. If > > columnDescriptions is null, then it is assumed that all values are > > strings, and the number of the columns is equal to the number of the > > columns in the first line of the reader. If headerRow is set to true, > > and the columnDescriptions does not contain the labels of the columns, > > then the headerRow values are used as the column labels. > > headerRow - True if there is an header row. In that case, the > > first line of the csv is taken as the header row. > > locale - An optional locale in which to parse the input csv file. > > If null, uses the default from LocaleUtil#getDefaultLocale. > > > So it looks like the columnDescriptions needs to be changed to specify > > the data types. I cannot seem to find an example of what the syntax > > would look like for this code. > > > Can you show me what the syntax looks like or where I can look at an > > example. > > > As you may have guess by now, I am not much of a java expert -- more > > of a php guy :-) > > > ....George > > > On Nov 30, 8:20 am, Viz Kid <[email protected]> wrote: > > > First, in order to make sure that the problem indeed lies with the second > > > column type, you can look at the response itself and verify what are the > > > returned column types (this should be in json format). If indeed both > > > columns are strings, you need to look at your code which generates the > > > DataTable from the csv file. Otherwise, the problem is someplace else. > > > > If you are using our external Java library to create the DataTable from > > the > > > csv, you need to specify the the column types (this is not part of the > > csv > > > file itself). The general documentation of the library is > > > here< > >http://code.google.com/apis/visualization/documentation/dev/dsl_javad...>, > > > you can look inside the package > > > com.google.visualization.datasource.util<com/google/visualization/datasourc > > e/util/package-frame.html> > > > , and specifically, the CsvDataSourceHelper <CsvDataSourceHelper.html> > > class > > > which can construct the DataTable from the csv file/url. The read > > function > > > also expects a the type for each of the columns. > > > > Hope it will work now, > > > Viz Kid. > > > > On Mon, Nov 30, 2009 at 3:01 PM, gman <[email protected]> wrote: > > > > Thanks Viz Kid --- That would make sense. I just created the csv file > > > > using the linux vi editor and saving as a .csv file. > > > > > Does it have to be created a special way? > > > > > I thought a csv file was just a text file with comma separating the > > > > data fields, with each record on a new line. Am I missing something?. > > > > > On Nov 29, 5:26 pm, Viz Kid <[email protected]> wrote: > > > > > Hi. > > > > > > Is it possible that the data table which is constructed from the csv > > has > > > > > both columns type to be 'string' and not one 'string' and one > > 'number'? > > > > If > > > > > this is the case, the outcome is indeed that no gauge is being > > displayed. > > > > > > Viz Kid > > > > > > On Sun, Nov 29, 2009 at 2:26 PM, gman <[email protected]> wrote: > > > > > > I just started playing with this yesterday and have run into a > > problem > > > > > > I just cannot seem to get by. > > > > > > > Using the sample code for gauges I can display the gauges fine. > > When I > > > > > > get the data from a csv file, no gauges are displayed. However if I > > > > > > change to display a table, it displays just fine. The csv file > > looks > > > > > > like this: > > > > > > > Label,Value > > > > > > Memory,80 > > > > > > CPU,55 > > > > > > Network,68 > > > > > > > This does work: > > > > > > > // var data = response.getDataTable(); > > > > > > var data = new google.visualization.DataTable(); > > > > > > data.addColumn('string', 'Label'); > > > > > > data.addColumn('number', 'Value'); > > > > > > data.addRows(3); > > > > > > data.setValue(0, 0, 'Memory');// data.setValue(0, > > 1, > > > > > > 80); > > > > > > data.setValue(1, 0, 'CPU');// data.setValue(1, 1, > > > > > > 55); > > > > > > data.setValue(2, 0, 'Network'); > > > > > > data.setValue(2, 1, 68); > > > > > > > var chart = new google.visualization.Gauge > > > > > > (document.getElementById('char > > > > > > t_div')); > > > > > > chart.draw(data, null); > > > > > > > This does not work: > > > > > > > var data = response.getDataTable(); > > > > > > // var data = new google.visualization.DataTable(); > > > > > > // data.addColumn('string', 'Label'); > > > > > > // data.addColumn('number', 'Value'); > > > > > > // data.addRows(3); > > > > > > // data.setValue(0, 0, 'Memory');// > > data.setValue(0, > > > > > > 1, 80); > > > > > > // data.setValue(1, 0, 'CPU');// data.setValue(1, > > 1, > > > > > > 55); > > > > > > // data.setValue(2, 0, 'Network'); > > > > > > // data.setValue(2, 1, 68); > > > > > > > var chart = new google.visualization.Gauge > > > > > > (document.getElementById('char > > > > > > t_div')); > > > > > > chart.draw(data, null); > > > > > > > Yet --- Exactly the same code, but changing to a table does work: > > > > > > > var data = response.getDataTable(); > > > > > > // var data = new google.visualization.DataTable(); > > > > > > // data.addColumn('string', 'Label'); > > > > > > // data.addColumn('number', 'Value'); > > > > > > // data.addRows(3); > > > > > > // data.setValue(0, 0, 'Memory');// > > data.setValue(0, > > > > > > 1, 80); > > > > > > // data.setValue(1, 0, 'CPU');// data.setValue(1, > > 1, > > > > > > 55); > > > > > > // data.setValue(2, 0, 'Network'); > > > > > > // data.setValue(2, 1, 68); > > > > > > > var chart = new google.visualization.Table > > > > > > (document.getElementById('char > > > > > > t_div')); > > > > > > chart.draw(data, null); > > > > > > > Any ideas or suggestions? > > > > > > > -- > > > > > > > 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]<google-visualization- > > > > > > api%[email protected]> > > <google-visualization-api%[email protected]<google-visualizati > > on-api%[email protected]> > > > > > <google-visualization-api%[email protected]<google-visualizati > > > > on-api%[email protected]> > > <google-visualization-api%[email protected]<google-visualiza > > tion-api%[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]<google-visualization- > > > > api%[email protected]> > > <google-visualization-api%[email protected]<google-visualizati > > on-api%[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]<google-visualization- > > api%[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.
