Time value in Line Chart

62 views
Skip to first unread message

R22MPM

unread,
Mar 9, 2012, 8:28:11 AM3/9/12
to google-visua...@googlegroups.com
I'm not sure if this is possible but i wont to display on a line graph the time taken for a particular process to run. This will be the difference between the start of the process and the end.

Sample of file;

Date, TimeTaken
20120301, 06:30:00:000
20120302, 04:30:00:000
20120303, 05:30:00:000

asgallant

unread,
Mar 9, 2012, 10:30:33 AM3/9/12
to google-visua...@googlegroups.com
You can do this.  Put the date in the first column of the DataTable object (with type 'date') as a Date object.  Store the running time in the second column (as type 'number'), using whatever unit value you want on the axis, stored as a floating point number.  You can then set the formatted value of the output to a readable running time.  Something like this: http://jsfiddle.net/pJtTw/

R22MPM

unread,
Mar 9, 2012, 11:10:35 AM3/9/12
to google-visua...@googlegroups.com
Thanks again for this, what format are you pulling the date in as?

[new Date(2012, 0, 1), 5.6372]

5.6372?

Thanks

asgallant

unread,
Mar 9, 2012, 11:38:50 AM3/9/12
to google-visua...@googlegroups.com
The Date object was just created in standard js Date notation (year, month, day), where months are zero-indexed.

I entered the time in hours (all numbers were random, but 5.6372 hours is (roughly) 5 hours, 38 minutes, and 13 seconds).  You need to have this value measured in whatever units you want on your axis (I chose hours).  You could store them in other formats (like microseconds) and then use a DataView to translate them into whatever units you want.

R22MPM

unread,
Mar 9, 2012, 12:08:14 PM3/9/12
to google-visua...@googlegroups.com
Thanks almost there now just one last issue, to get the second column to convert to a number i need to copy the datatable into a view to convert.

The setFormattedValue doesnt appear to work with the view

Any ideas?

Thanks

asgallant

unread,
Mar 9, 2012, 1:27:51 PM3/9/12
to google-visua...@googlegroups.com
You can return the value in the view as an object, with properties 'v' (value) and 'f' (formatted value):

function (dtrow{
    /*
        calculate value and formatted value to return
    */
    return {vvaluef'Value formatted as a string'};

R22MPM

unread,
Mar 9, 2012, 3:07:11 PM3/9/12
to google-visua...@googlegroups.com
On further investigation the issue looks like its with the conversion from string to number, it seems to be rounding to a whole number.

i tried the following, but both round the number for some reason

view.setColumns([0, {calc:converttonumber, type:'number', label: "TEST"}]);
        function converttonumber(data, rowNum){
        return Math.floor(data.getValue(rowNum, 1) / 1);
            }

and

function convertonumber(data, rowNum) {
    return parseInt(data.getValue(rowNum, 1));
}

asgallant

unread,
Mar 9, 2012, 3:38:31 PM3/9/12
to google-visua...@googlegroups.com
Math.floor() rounds the number down, and parseInt() parses the number as an integer.  I assumed that's what you wanted, seeing as how you used Math.floor(); if you need floating point values, use parseFloat() to parse a string as a floating point number.
Reply all
Reply to author
Forward
0 new messages