Type Mismatch for Number in Google Chart API

I have an array and a second column with values โ€‹โ€‹similar to this 2050.878456 , and inside my javascript function to create an Area Chart I did the following

 function drawVisualization() { var data = null; data = new google.visualization.DataTable(); data.addColumn('string', 'Date'); data.addColumn('number', 'Value'); data.addRows(myArrayCreated); // Create and draw the visualization. var ac = new google.visualization.AreaChart(document .getElementById('visualization_chart')); ac.draw(data, { title : 'Results', isStacked : true, width : 700, height : 400, vAxis : {title : "kW"}, hAxis : {title : "Day"} }); } 

however, I get this Type mismatch. Value 2050.878456 does not match type number in column index 1 error Type mismatch. Value 2050.878456 does not match type number in column index 1 Type mismatch. Value 2050.878456 does not match type number in column index 1 , but it also cannot be a string type, why can I get this error and how to fix it?

+6
source share
2 answers

Try passing Value as a string , and then do parseFloat . Something like that:

 data.addColumn('string', 'Value'); for (var i=0;i<myArrayCreated.length;i++){ myVal = parseFloat($.trim(myArrayCreated[i][1])); data.addRow([i, {v: myVal, f: myval.toFixed(6)}]); } 
+7
source

I noticed the same problem.

does not work:

 data.addRow([v, obd[v].engine_rpm]); 

working:

 data.addRow([v, Number(obd[v].engine_rpm)]); 

wtf

+2
source

Source: https://habr.com/ru/post/971237/


All Articles