Re: [visualization-api] Error when add column date type using in google bar chat..

17 views
Skip to first unread message

Daniel LaLiberte

unread,
Feb 13, 2018, 2:09:41 PM2/13/18
to Google Visualization API
Does it work if you leave out the "new " before the Date?  The string notation (useful with JSON) does not support the extra "new " which is a JavaScript instance constructor notation.

On Tue, Feb 13, 2018 at 1:49 AM, anup sharma <anupsharma.te...@gmail.com> wrote:
This is my code: 

 var data = new google.visualization.DataTable();
              data.addColumn('date', 'Value');
              data.addColumn('number', 'Value');

              var jsonData =   [ { "added_date" : "new Date(2018,0,31)",
                                "count"      : "42" },
                              { "added_date" : "new Date(2018,1,1)",
                                "count"      : "127" },
                              { "added_date" : "new Date(2018,1,2)",
                                "count"      : "26" },
                              { "added_date" : "new Date(2018,1,3)",
                                "count"      : "94" },
                              { "added_date" : "new Date(2018,1,5)",
                                "count"      : "14" },
                              { "added_date" : "new Date(2018,1,6)",
                                "count"      : "31" },
                              { "added_date" : "new Date(2018,1,7)",
                                "count"      : "2" },
                              { "added_date" : "new Date(2018,1,8)",
                                "count"      : "214" },
                              { "added_date" : "new Date(2018,1,9)",
                                "count"      : "26" },
                              { "added_date" : "new Date(2018,1,10)",
                                "count"      : "26" },
                              { "added_date" : "new Date(2018,1,11)",
                                "count"      : "10" },
                              { "added_date" : "new Date(2018,1,12)",
                                "count"      : "102" },
                              { "added_date" : "new Date(2018,1,13)",
                                "count"      : "6" } ]; 
              for (var i = 0; i < jsonData.length; i++) {
                  
                   data.addRow([jsonData[i].added_date,parseInt(jsonData[i].count)]);
              }
                var options = {
                    title: 'Date wise Usage'
                };
              var chart = new google.visualization.ColumnChart(document.getElementById("columnchart"));
              chart.draw(data, options);

when execute i have got the error 
Uncaught Error: Type mismatch. Value new Date(2018,0,31) does not match type date in column index 0

--
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 google-visualization-api+unsub...@googlegroups.com.
To post to this group, send email to google-visualization-api@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-visualization-api/9ebd54fa-ecf8-4d92-8bbb-2130e3052251%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Reply all
Reply to author
Forward
0 new messages