You cannot overwrite the contents of a column with a different data type.  
You could insert a new column, fill it with dates, and then delete the old 
column:

data.insertColumn(1, 'date', 'date');
for (var i = 0; i < data.getNumberOfRows(); i++) {
    var dateString = data.getValue(row, 0).toString();
    var year = dateString.substring(0, 4);
    var month = dateString.substring(4, 2); // javascript uses 0-indexed 
months (ie, January is 0 not 1), so you may need to subtract 1 from this if 
you haven't already accounted for it
    var day = dateString.substring(6, 2);
    data.setValue(1, i, new Date(year, month, day));
}
data.removeColumn(0);

You can then format the date column with a DateFormatter.

On Monday, April 7, 2014 5:57:01 PM UTC-4, cyb wrote:
>
> Hi,
>
> i want not add new columns.. is there no way that i can take the 'date' 
>  column from the DataTable and parse it to a column with type =date ? i 
> thought i can overwrite values in a DataTable?
>
> data = new google.visualization.arrayToDataTable([
>                     ['date','New York','Austin','San 
> Francisco','Country','Popularity'],
>                     ['20111001',2,3,15,'Germany',200],
>                     ['20111002',5,6,19,'Brazil',400],
>                     ['20111003',8,9,23,'United States',300],
>                     ['20111004',11,12,35,'RU',700]
>                 ];)
>
> at the moment i have this data, and the "date" colum is parsed to a 
> number..
>
> can i not write a calc function that does the same as your code with the 
> dataView ?
>
> and second questions:
>
> yout have set "return {v: date, f: formatter.formatValue(date)};" for 
> what is v:date ? for the formatted value? because you have already set the 
> type to date with "dataView.setColumns([{
>     type: 'date',...."
>
>
>

-- 
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/d/optout.

Reply via email to