Thanks for that. I don't know how I missed calc() cos I did go looking.
obviously, the beer goggles got in the way.


On Tue, Sep 17, 2013 at 12:18 AM, asgallant <[email protected]>wrote:

> Forgot link to DataView documentation:
> https://developers.google.com/chart/interactive/docs/reference#DataView
>
>
> On Monday, September 16, 2013 10:13:49 AM UTC-4, asgallant wrote:
>>
>> The DataView object has the built-in capability to calculate new columns
>> based on data in the existing columns:
>>
>> // data is the DataTable object to base the view off of
>> var view = new google.visualization.DataView(**data);
>> // the #setColumns  method takes an array of column indices and objects
>> describing calculated columns, eg:
>> // use the first, second, and third columns in the DataTable, plus a
>> calculated column that shows the average of the second and third:
>> view.setColumns([0, 1, 2, {
>>     type: 'number',
>>     label: 'average',
>>     calc: function (dt, row) {
>>         // the function for a calculated column takes two arguments: the
>> DataTable and the row index
>>         // use the row index to pull data from the appropriate columns
>> from the DataTable to generate your returned data
>>         // eg, return the average of the second and third columns:
>>         return (dt.getValue(row, 1) + dt.getValue(row, 2)) / 2;
>>     }
>> }]);
>>
>> You then use the DataView in place of a DataTable when you want to draw
>> your visualization.
>>
>> On Monday, September 16, 2013 2:04:33 AM UTC-4, ggm wrote:
>>>
>>> Is there a preferred idiom to do the legal javascript equivalent of:
>>>
>>> map(lambda: x,a,b,c, myfunction(): row[x].col[c] =
>>> my_function(row[x].col[a], row[x].col[b]) for x in range(0,len(row)))
>>>
>>> so we can eg construct on-the-fly smoothed state, differences, % &c &c
>>> from data previously loaded via json?
>>>
>>> I can trivially code it[*]. I just wondered if bitter experience has led
>>> to a safe, sensible way to do it.
>>>
>>> [*] its going to run like a dog, and probably be hugely unsafe, and have
>>> to deal with null args and a whole heap of stuff which smarter people could
>>> do better, But I would have thought we'd all wind up needing to construct
>>> data columns on-the-fly which are a function of other columns we have
>>> in-hand.
>>>
>>  --
> 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.
>

-- 
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.

Reply via email to