PHP - Google Charts - Type mismatch. Value 2018-04-01 00:00:53 does not match type date in column index

190 views
Skip to first unread message

Dragan Mestrovik

unread,
May 11, 2018, 1:50:31 AM5/11/18
to Google Visualization API
Hi,

When i tried to show the data in a chart, i am getting the below error. Can anyone help me why it is not converting the date "2018-04-01 00:00:53"?

Type mismatch. Value 2018-04-01 00:00:53 does not match type date in column index

And my code is

var dataTable = new google.visualization.DataTable();
      dataTable.addColumn('string','stock');
      dataTable.addColumn('date','Time');
      dataTable.addColumn('number','price');

      
     var json=$.parseJSON( jsonData);
     
     for (var i=0;i<json.length;i++) {
           delete json[i].id;
           delete json[i].LastTradePrice;
           delete json[i].Min24hrs;
           delete json[i].LowestAsk;
           delete json[i].Max24hrs;
           delete json[i].HighestBid;
           var row = [];
           for (var item in json[i]) {
             row.push(json[i][item]);
           } 
           dataTable.addRow(row);
        }

     var data =google.visualization.Table(dataTable,true);
     var chart = new google.visualization.CandlestickChart(document.getElementById('chart'));
     chart.draw(data, {width: 400, height: 240});

Dragan Mestrovik

unread,
May 11, 2018, 2:45:03 AM5/11/18
to Google Visualization API
I have change the code as below.. But still getting the same error

 var dataTable = new google.visualization.DataTable();
      dataTable.addColumn('string','stock');
      dataTable.addColumn('date','Time');
      dataTable.addColumn('number','price');
      
     var json=$.parseJSON(jsonData);
     
      var formatDate = new google.visualization.DateFormat({
        pattern: 'yyyy-MM-dd hh:mm:ss' //'yyyy-MM-dd hh:mm:ss'
      });

     json.forEach(function (row) {
        var rowDate = new Date(row.Time);
        document.write(row.Time + "  " + formatDate.formatValue(rowDate));
        dataTable.addRow([
                    row.stock,
                    //formatDate.formatValue(rowDate),
                    row.Time,
                    row.price
        ]);
      });
Reply all
Reply to author
Forward
0 new messages