Dates on the axis in the Google Charts chart line

A newbie question is asked here, but how do I use dates for the x axis in a Google chart diagram ?

When I use the new date (...), I get the error "Unused errors: date and date column types are not supported"

google.load("visualization", "1", {packages:["corechart"]}); google.setOnLoadCallback(drawChart); function drawChart() { var data = google.visualization.arrayToDataTable([ ['Datum','Person1','Person2','Person3'], [new Date(2012, 12, 19, 0, 0, 0),'5072.0537223002','5072.0537223002','5074.2809630567'], [new Date(2012, 12, 20, 0, 0, 0),'5072.0537223002','5072.0537223002','5074.2809630567'], ]); var options = {}; var chart = new google.visualization.LineChart(document.getElementById('chart_div')); chart.draw(data, options); } 

(Using rows with even spaces on the x axis would be acceptable, but when I try to use the rows "The data column for axis No. 0 cannot be a row of type")

+4
source share
2 answers

How to convert date to string and just use Date without new , as shown below:

  google.load("visualization", "1", {packages:["corechart"]}); google.setOnLoadCallback(drawChart); function drawChart() { var data = google.visualization.arrayToDataTable([ ['Datum','Person1','Person2','Person3'], [Date(2012, 12, 19, 0, 0, 0).toString(),'5072.0537223002','5072.0537223002','5074.2809630567'], [Date(2012, 12, 20, 0, 0, 0).toString(),'5072.0537223002','5072.0537223002','5074.2809630567'], ]); var options = {}; var chart = new google.visualization.LineChart(document.getElementById('chart_div')); chart.draw(data, options); } 

Edit: You can follow their example at this link:

https://google-developers.appspot.com/chart/interactive/docs/customizing_axes

Edit 2:

This is what I was able to do: http://jsfiddle.net/ANC9H/2/

  google.load("visualization", "1", {packages:["LineChart"]}); google.setOnLoadCallback(drawChart); function drawChart() { var data = new google.visualization.DataTable(); data.addColumn('date', 'Date'); data.addColumn('number', 'persone1'); data.addColumn('number', 'persone2'); data.addColumn('number', 'persone3'); data.addRows([ [new Date(2008, 1 ,1),0.7,0.8,0.6], [new Date(2008, 1 ,7),0.5,0.55,0.9] ]); var options = {}; var chart = new google.visualization.LineChart(document.getElementById('chart_div')); chart.draw(data, options); } 

Hope this helps.

+8
source

This is because you are using arrayToDataTable (). If you use DataTable (), the error message will disappear. See This Post: Date Axis Column Chart Does Not Work

0
source

All Articles