VIz Kid, can you post that example? On Jun 24, 9:58 pm, NA <[email protected]> wrote: > So can you present an example using DataView? I can't see a > straightforward way to do this, but I'll give you the benefit of the > doubt. Show me how you'd do the following: > > table has these columns: > > 0 1 2 3 4 5 6 7 > id, sector, price, shares, weight, f1, f2, f3 > > I want to aggregate this by sector. The aggregation functions for > price, f1, f2, and f3 is a weighted average. The aggregation for > shares and weight is a sum. The aggregation for id and sector is to > return the string "Many" if there are multiple values in that column, > or if all the entries are the same return that value. > > Such aggregation functions might look like: > > function WeightedAverage(q,w) { > var wsum = 0; > for (i=0;i<w.length;i++) {wsum+= w[i]*q[i];} > return wsum; > > } > > function AllSameOrMany(c) { > var r = c[0]; > for (var i=0;i<c.length;i++) {if (r !=c[i]){return 'Many';}}; > return r; > > } > > Note that the WeightedAverage function is a general function that > doesn't require the weight to always be in column 4. It also doesn't > know what Tables are. It's used in many places; its existence > predates the google visualization API. This is important for > reusability, maintainability, and interoperability across many > libraries. > > What I'd like to do is; > > bySector = new google.visualization.data.group(table,[1], > [ {column:0, aggregation:AllSameOrMany, type:'string'} > ,{column:[2,4],aggregation:WeightedAverage,type:'number'} > ,{column:3, aggregation:google.visualization.data.sum,type:'number'} > ,{column:4, aggregation:google.visualization.data.sum,type:'number'} > ,{column:[5,4], aggregation:WeightedAverage,type:'number'} > ,{column:[6,4], aggregation:WeightedAverage,type:'number'} > ,{column:[7,4], aggregation:WeightedAverage,type:'number'} > ] > ); > > Since this syntax doesn't exist, can you show me how to do this with > google.visualization.data.group or with DataViews, without having to > create special versions of my aggregation functions? > > In my case, I used currying to wrap functions like WeightedAverage in > a way to accommodate the grouping and DataView APIs. > > But I'd like to learn a cleaner way of doing this. > > thanks,
-- 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.
