var data = new google.visualization.arrayToDataTable([['date','column1','column2'],[20111001,2,3],[20111002,5,6],[20111003,8,9],[20111004,11,12] ]);var dataView = new google.visualization.DataView(data);var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(dataView, options);
Hi,
ok great this works, but i have another question :)
When i use the line chart example from my first post, i use the "dataView.setColumns(0,1);" to show or hide specific Columns..
At the moment is use the column ID´s 0,1 or whatever.. But can i use instead of the Column numbers the name of the columns ?
If i have this Data:
var data = new google.visualization.arrayToDataTable([
['date','New York,'Austin'],
[20111001,2,3],
[20111002,5,6],
[20111003,8,9],
[20111004,11,12] ]);
var dataView = new google.visualization.DataView(data);
can i say dataView.setColumns('date','Austin'); ??
Best regards
cyb
var options = {title: 'New Values',animation:{duration: 1000,easing: 'in'},isStacked: false,pointSize: 3};
chart.draw(dataView, options); // redraw chart
dataView.setColumns([{type: 'date',label: data.getColumnLabel(0),calc: function (dt, row) {var dateString = dt.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 itvar day = dateString.substring(6, 2);return new Date(year, month, day);}}, 1, 2]);
google.visualization.DateFormat({pattern: "EEE,
MMM d, ''yy"}); this is from the examples.. ?
var data = new google.visualization.arrayToDataTable([['date','column1','column2'],[20111001,2,3],[20111002,5,6],[20111003,8,9],[20111004,11,12] ]);
[2011-10-04,11,12] ]);
var format = d3.time.format("%Y-%m-%d"); format.parse("2011-01-01"); // returns a Date format(new Date(2011, 0, 1)); // returns a string
var dataView = new google.visualization.DataView(data);
dataView.setColumns([{type: 'date',label: data.getColumnLabel(0),calc: function (dt, row) {var dateString = dt.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 itvar day = dateString.substring(6, 2);return new Date(year, month, day);}}, 1, 2]);
ou 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 itvar 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.