Thanks a ton your solution worked perfectly !
On Tuesday, 4 February 2014 17:13:13 UTC+1, asgallant wrote:
>
> In javascript, you can use the group function to get the max value of
> license (example code assumes date is a string in column 0 and license is a
> number in column 1):
>
> var maxLicenseByDate = google.visualization.data.group(data, [0], [{
> type: 'number',
> label: data.getColumnLabel(1),
> aggregation: google.visualization.data.max
> }]);
>
> and then filter your data by date:
>
> var dateFilteredView = new google.visualization.DataView(maxLicenseByDate
> );
> dateFilteredView.setRows(data.getFilteredRows([{column: 0, value:
> '01/02/2013'}]);
>
>
> On Tuesday, February 4, 2014 10:56:10 AM UTC-5, Ashok Kumar wrote:
>>
>> Thanks asgallant for the response but i am still not clear. My requirment
>> is to basically get the max value in a particular date range. To be more
>> precise is it possible to execute the build the below query in Java scripts
>> with a CSV file.
>>
>> Select max(license) where Date = '01/02/2013'
>>
>> Also find below the code that i have written so far. I am not sure if i
>> can achieve my above requirment using getFilteredRows. Also I would prefer
>> a solution to use the query language to retrieve rows rather than the
>> getFilteredRows on datatable.
>>
>> <!DOCTYPE html>
>> <html>
>> <head>
>> <title>Google Chart Example</title>
>> <script src="https://www.google.com/jsapi"></script>
>> <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
>> <script src="http://localhost/jquery.csv-0.71.js"></script>
>> <script type="text/javascript">
>> google.load("visualization", "1", {packages:["gauge"]});
>> </script>
>> <script>
>> function drawChart()
>> {
>> //$.get("http://localhost/output.csv",function(csvString)
>> //{
>> var queryOptions =
>> {
>> //csvColumns:
>> ['string','string','string','date','string','number','number','number','string','string','string','number','string','string','string','string','string'],
>> //csvColumns:
>> ['string','string','string','string','string','string','string','string','string','string','string','string','string','string','string','string','string']
>> csvColumns: ['string','number','number'],
>> csvHasHeader: true
>> }
>> //csvUrl= 'http://localhost/output.csv';
>> csvUrl= 'http://localhost/temperatures.csv';
>> var query = new google.visualization.Query(csvUrl,queryOptions);
>> //var query = new google.visualization.Query('
>> http://spreadsheets.google.com/tq?key=pCQbetd-CptGXxxQIG7VFIQ&range=B1:D11&pub=1'
>> );
>> //var arrayData = $.csv.toArrays(csvString, {onParseValue:
>> $.csv.hooks.castToScalar});
>> query.setQuery('SELECT A,B WHERE C > 6');
>> query.send(handleQueryResponse);
>> function handleQueryResponse(response)
>> {
>> //alert(response.status);
>> if (response.isError())
>> {
>> alert('Error in query: ' + response.getMessage() + ' ' +
>> response.getDetailedMessage());
>> return;
>> }
>> var data = response.getDataTable();
>> var dataView1 = new google.visualization.DataView(data);
>> dataView1.setRows(data.getFilteredRows([{minValue: 6,column: 2}]));
>> dataView1.setColumns([1]);
>> var chart = new
>> google.visualization.Gauge(document.getElementById('chart'));
>> chart.draw(dataView1,{width: 400, height: 250,redFrom: 18, redTo:
>> 20,yellowFrom:15, yellowTo: 17,minorTicks: 5,min: 1,max:
>> 20,animation:{duration: 400,easing: 'linear'}});
>> }
>> }
>> google.setOnLoadCallback(drawChart);
>> </script>
>> </head>
>> <body>
>> <div id="chart">
>> </div>
>> </body>
>> </html>
>>
>>
>> On Friday, 31 January 2014 15:09:00 UTC+1, Ashok Kumar wrote:
>>
>>> Hi,
>>>
>>> I am not able to filter and display the gauge chart based on my query.
>>> Also the gauge chart is always displayed for the entire CSV data and not
>>> based on my query.Find below the code that i used.
>>>
>>> <!DOCTYPE html>
>>> <html>
>>> <head>
>>> <title>Google Chart Example</title>
>>> <script src="https://www.google.com/jsapi"></script>
>>> <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
>>> <script src="http://localhost/jquery.csv-0.71.js"></script>
>>> <script type="text/javascript">
>>> google.load("visualization", "1", {packages:["gauge"]});
>>> </script>
>>> <script>
>>> function drawChart()
>>> {
>>> //$.get("http://localhost/output.csv",function(csvString)
>>> //{
>>> var queryOptions =
>>> {
>>> //csvColumns:
>>> ['string','string','string','date','string','number','number','number','string','string','string','number','string','string','string','string','string'],
>>> //csvColumns:
>>> ['string','string','string','string','string','string','string','string','string','string','string','string','string','string','string','string','string']
>>> csvColumns: ['string','number'],
>>> csvHasHeader: true
>>> }
>>> //csvUrl= 'http://localhost/output.csv';
>>> csvUrl= 'http://localhost/temperatures.csv';
>>> var query = new google.visualization.Query(csvUrl,queryOptions);
>>> //var query = new google.visualization.Query('
>>> http://spreadsheets.google.com/tq?key=pCQbetd-CptGXxxQIG7VFIQ&range=B1:D11&pub=1'
>>> );
>>> //var arrayData = $.csv.toArrays(csvString, {onParseValue:
>>> $.csv.hooks.castToScalar});
>>> query.setQuery('select B,C where C > 6');
>>> query.send(handleQueryResponse);
>>> function handleQueryResponse(response)
>>> {
>>> if (response.isError())
>>> {
>>> alert('Error in query: ' + response.getMessage() + ' ' +
>>> response.getDetailedMessage());
>>> return;
>>> }
>>> var data = response.getDataTable();
>>> //alert(data[1,1]);
>>> //var dataView1 = new google.visualization.DataView(data);
>>> //dataView1.setColumns([1]);
>>> var chart = new
>>> google.visualization.Gauge(document.getElementById('chart'));
>>> chart.draw(data,{width: 400, height: 250,redFrom: 18, redTo:
>>> 20,yellowFrom:15, yellowTo: 17,minorTicks: 5,min: 1,max:
>>> 20,animation:{duration: 400,easing: 'linear'}});
>>> }
>>> }
>>> google.setOnLoadCallback(drawChart);
>>> </script>
>>> </head>
>>> <body>
>>> <div id="chart">
>>> </div>
>>> </body>
>>> </html>
>>>
>>> This is my CSV Data.
>>>
>>> Label,License_Utilized,validation
>>> License,10,5
>>> License1,18,7
>>>
>>> Thanks,
>>> Ashok
>>>
>>>
>>>
>>>
>>>
>>>
--
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.