I got that solved.  I just forgot the new.  It was something to the effect 
of "Cannot call setColumns on undefined".

I do need help however on figuring out why it seems the values being used 
for the calculations are the column numbers instead of the column values.

var view = new google.visualization.DataView(non_grouped);
/* Non_grouped Columns
0 - Date, 1 - Shift, 2-Press, 3- Mold,
4 - Downtime, 5 - Scheduled, 6 - Uptime, 
7 - Target, 8- Scrapped, 9- Made
*/
view.setColumns([0,1,2,3,
{calc: getAvail(4,6), type: 'number'},
{calc: getPerf(9,7,6), type: 'number'},
{calc: getQual(9, 8), type: 'number'},
{calc: getOEE(4,7,6,9,8), type: 'number'}]);
/*  View Columns
0 - Date, , 1 - Shift, 2 - Press, 3 - Mold
4 - Availability, 5 - Performance, 6 -  Quality, 7 - OEE
*/
showThis = new google.visualization.data.group(view, [0],
[{column: 4, aggregation: google.visualization.data.avg, type: 'number'},
{column: 5, aggregation: google.visualization.data.avg, type: 'number'},
{column: 6, aggregation: google.visualization.data.avg, type: 'number'},
{column: 7, aggregation: google.visualization.data.avg, type: 'number'}]);
     var chart = new 
google.visualization.LineChart(document.getElementById('chart-oee'));
     chart.draw(showThis, options);
    $(curTab).show();
}
});
}
function getAvail(d,u){
return u/(u+d);
}
function getPerf(p,t,u){
return (p*t)/u;
}
function getQual(p, s){
return (p-s)/p;
}
function getOEE(d,t,u,p,s){
var avail = getAvail(d,u);
var perf = getPerf(p,t,u);
var qual = getQual(p,s);
return avail*perf*qual;
}

On Tuesday, January 8, 2013 11:35:44 AM UTC-5, asgallant wrote:
>
> What is the exact error being thrown here?
>
> On Tuesday, January 8, 2013 11:28:50 AM UTC-5, Michelle Stewart wrote:
>>
>> I am doing something very similar so I was using this code, but 
>> apparently I am missing something obvious because my view isn't working.
>>
>> I am using arrayToDataTable because of the data I have, but 
>> <code>
>> var non_grouped = google.visualization.arrayToDataTable(oeeChartsData);
>> var view = google.visualization.DataView(non_grouped);
>> /* Non_grouped Columns
>> 0 - Date, 1 - Shift, 2-AAA, 3- BBB
>> 4 - Downtime, 5 - Scheduled, 6 - Uptime, 
>> 7 - Target, 8- Scrapped, 9- Made
>> */
>> view.setColumns([0,1,2,3,
>> {calc: getAvail(4,6), type: 'number'},
>> {calc: getPerf(9,7,6), type: 'number'},
>> {calc: getQual(9, 8), type: 'number'},
>> {calc: getOEE(4,7,6,9,8), type: 'number'}]);
>> </code>
>> errors on the setColumns line because the view never got created!  All my 
>> functions work, any ideas what could be wrong?
>> non_grouped is a dataTable just fine.  
>>
>> Thanks in advance,
>> Michelle
>>
>> On Wednesday, June 29, 2011 3:43:15 AM UTC-4, Viz Kid wrote:
>>>
>>>
>>> Hi
>>>
>>> I stated that this can be done using a DataView, but I did not say that 
>>> it would be as clean as you would like, especially satisfying your request 
>>> to use the general existing weighted average function as is. If the 
>>> WeightedAverage function is indeed what you wrote (I did not see any 
>>> normalization there so I wasn't sure), you can indeed get the desired 
>>> outcome using first a DataView to create the weighted columns [2,5,6,7] (by 
>>> multiplying their value by the weight) and then applying the group call as 
>>> you did it where replacing the WeightedAverage with the sum function.
>>>
>>> I agree that it would be more natural to have the syntax as you wrote it 
>>> available for this use case but currently it simply does not exist.
>>>
>>> Here is a snippet of the code:
>>>
>>> view = new google.visualization.DataView(table);
>>> view.setColumns([
>>>   0,
>>>   1,
>>>   {calc: weightedColumn(2, 4), type: 'number'}, 
>>>   3,
>>>   4,
>>>   {calc: weightedColumn(5, 4), type: 'number'}, 
>>>   {calc: weightedColumn(6, 4), type: 'number'}, 
>>>   {calc: weightedColumn(7, 4), type: 'number'}]);
>>>
>>> bySector = new google.visualization.data.group(view, [1],
>>>  [ {column:0, aggregation:AllSameOrMany, type:'string'}
>>>   ,{column:2, aggregation:google.visualization.data.sum,type:'number'}
>>>   ,{column:3, aggregation:google.visualization.data.sum,type:'number'}
>>>   ,{column:4, aggregation:google.visualization.data.sum,type:'number'}
>>>   ,{column:5, aggregation:google.visualization.data.sum,type:'number'}
>>>   ,{column:6, aggregation:google.visualization.data.sum,type:'number'}
>>>   ,{column:7, aggregation:google.visualization.data.sum,type:'number'}
>>>  ]
>>> );
>>>
>>> function weightedColumn(dataColumnIndex, wightsColumnIndex) {
>>>   return function(dataTable, rowNum) {
>>>     return dataTable.getValue(rowNum, dataColumnIndex) 
>>> * dataTable.getValue(rowNum, weightsColumnIndex);
>>>   }
>>> }
>>>
>>> Best,
>>>   Viz Kid
>>>
>>> On Wed, Jun 29, 2011 at 5:04 AM, NA <[email protected]> wrote:
>>>
>>>> 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.
>>>>
>>>>
>>>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Visualization API" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-visualization-api/-/AhAcXFwfizEJ.
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.

Reply via email to