There are two separate things being built there.  The first is the "series" 
option for the chart, which tells the chart how to display a data series. 
 The second is an array of columns; in this array, numbers reference column 
indices in the DataTable, so 0 references column 0 ("Month"), 1 references 
column 1 ("Project 1"), etc.  When we push objects into this array (instead 
of numbers), we are telling the chart to create some new columns along with 
the existing ones; lets break down the first one:

// add a 50% series
columns.push({
    label: '50%',
    type: 'number',
    calc: function (dt, row) {
        var sum = 0;
        for (var i = 1; i < dt.getNumberOfColumns(); i++) {
            sum += dt.getValue(row, i);
        }
        return sum * 0.5;
    }
});

Here we are adding a new column that the API will calculate on the fly. 
 The "label" parameter tells the chart what to call the column, the "type" 
parameter tells the chart what the type of data is, and the "calc" 
parameter gives the chart a function with which to calculate a value for 
each cell in the column.  The API calls this function once per row of data 
in the DataTable, passing a DataTable reference and row index to the 
function (called "dt" and "row" in my version).  The function then takes 
those inputs and generates some value which gets returned as the value for 
this column in the row.

If you want to use existing columns for the lines instead of doing the 
calculation here, then you can skip the whole view process entirely; just 
create the "series" option with each series type set as you like.  See an 
example: http://jsfiddle.net/asgallant/YVmtX/13/


On Friday, May 3, 2013 6:35:39 PM UTC-4, Minh Huynh wrote:
>
> Thank you. That's a lot better.
> Now, my question about the "push()" 
>
> 1. When you use it for the bar, it looks like you just create 5 spaces, in 
> the code the while n = 0 to the number of column in dataset, and you use 
> push(i), at this time, those spaces don't have value yet right? since the 
> value of i is just 0, 1, 2, 3, 4. It's not the value in the dataset. I dont 
> know which code line that u pass value of the dataset to the chart.
>
> 2. Then when you create the line chart, it seemed like you put the actual 
> value into it, push( ... return value* 0.7), so as question #1, here I can 
> see that you put value into the chart, Line chart. You passed the % of sum.
>
>
> What if i pick out 2 lines in the dataset to make it Line chart instead of 
> the %? can i pass the dataset value into the push()?
>
> I hope you understand what I'm asking since I don't know how to put it 
> another way, cuz I'm confused too.
>
>
> On Friday, April 12, 2013 9:24:36 AM UTC-7, Minh Huynh wrote:
>>
>> Hello everyone. First off I'm sorry I cannot post the sample of the chart 
>> that I need your help on creating.
>>
>> Every month I update this chart. It's a bar chart showing total number of 
>> hours that my group of 25 people work on a certain a mount of project in a 
>> month. Looking at a particularly column (each col is each month) chart, we 
>> can see how many hours the group spent on ea project. We have about 7 
>> projects that my group is working on. 
>>
>> So when I came to the group I only update the chart (in Excel by the 
>> way), what I do is just add in another Excel column then click on the chart 
>> and drag the hightlight grid over this month so the chart changes to this 
>> month. Problem is this month the chart broke, for some reason it just broke 
>> and we decide to re-create the chart not in Excel no more but on webpage.
>>
>> I'm fascinated by google chart, especially the interactive thing when I 
>> move my mouse onto the chart and it shows the number.
>>
>> I played with Google chart for a while but i can only created simple 
>> chart like pie, or bar. 
>>
>> I would greatly appreciate if anyone can create a sample type of this 
>> complicated chart.
>> Thank you
>>
>>

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to