javascript - Google Chart:Data column(s) for axis #0 cannot be of type string error -


i'm using google charts , keep getting error: data column(s) axis #0 cannot of type string. believe it's because in array i'm passing in, there string values there should number values. array n columns 8 rows. values on first row should numbers , values in first column should string , rest numbers. i'm grabbing values query string , when split them they're coming through string believe.

here's url query string: 1=day,04/01/2013,04/08/2013,04/15/2013,04/22/2013,04/29/2013,05/06/2013&2=monday,100,100,100,100,100,100&3=tuesday,100,100,100,100,100,100&4=wednesday,100,100,100,100,100,100&5=thursday,100,100,100,100,100,100&6=friday,100,100,100,100,100,100&7=saturday,100,100,100,100,100,100&8=sunday,100,100,100,100,100,100

and here's javascript:

function geturlvars() {     var vars = [], hash;     var hashes = window.location.href.slice(window.location.href.indexof('?') + 1).split('&');     for(var = 0; < hashes.length; i++)     {         hash = hashes[i].split('=');         vars.push(hash[0]);         vars[hash[0]] = hash[1];     }     return vars; }  var row1 = geturlvars()["1"]; var row2 = geturlvars()["2"]; var row3 = geturlvars()["3"]; var row4 = geturlvars()["4"]; var row5 = geturlvars()["5"]; var row6 = geturlvars()["6"]; var row7 = geturlvars()["7"]; var row8 = geturlvars()["8"];  var row1x=row1.split(",");  var row2x=row2.split(",");  var row3x=row3.split(",");  var row4x=row4.split(",");  var row5x=row5.split(",");  var row6x=row6.split(",");  var row7x=row7.split(",");  var row8x=row8.split(",");   var items = [row1x, row2x, row3x,row4x,row5x,row6x,row7x,row8x];          google.load("visualization", "1", {packages:["corechart"]});       google.setonloadcallback(drawchart);       function drawchart() {         var data = google.visualization.arraytodatatable(items);          var options = {           title: 'members open rate'         };          var chart = new google.visualization.linechart(document.getelementbyid('chart_div'));         chart.draw(data, options);       } 

any thought on how force values not in first row or column numbers instead of strings?

any thought on how force values not in first row or column numbers instead of strings?

use separate arrays:

var headers = [row1x]; var items = [row2x, row3x, row4x, row5x, row6x, row7x, row8x]; 

and stringify , parse array convert numeric strings numbers:

/* take string, create array, create string, replace quotes, return array */ var row3x = json.parse(json.stringify("3=tuesday,100,100,100,100,100".split(",")).replace(/"(\d+)"/g,"$1")) 

then concat 2 arrays:

var data = google.visualization.arraytodatatable(header.concat(items) ); 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -