Monday, June 3, 2024
88
rated 0 times [  94] [ 6]  / answers: 1 / hits: 17814  / 10 Years ago, mon, june 23, 2014, 12:00:00

I have an array and the second column with values like this 2050.878456 and inside my javascript function to create a Area Chart I made 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 error Type mismatch. Value 2050.878456 does not match type number in column index 1 however it cannot be a string type as well, why do I get this error and how to fix it?


More From » google-visualization

 Answers
87

Try passing the Value as string and then later do a parseFloat. Something like this:



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)}]);
}

[#70473] Thursday, June 19, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
freddiem

Total Points: 456
Total Questions: 116
Total Answers: 101

Location: Dominica
Member since Mon, Jan 4, 2021
3 Years ago
;