Data column(s) for axis #0 cannot be of type string error in google chart

后端 未结 5 1447
慢半拍i
慢半拍i 2021-01-05 20:29

I tried to populate google chart datatable in server side using PHP.I got JSON file properply, but the Chart not display in client Application. I got error-Data colu

相关标签:
5条回答
  • 2021-01-05 20:55

    You specify type of userid as number... but pass string.. thats causing the problem.

    I just wasted 30 mins with the opposite problem ...

    Your output json should look like :-

    {
      "cols":[
        {"id":"","label":"userid","pattern":"","type":"number"},
        {"id":"","label":"name","pattern":"","type":"string"}
       ],
      "rows":[
        {"c":[{"v":101},{"v":"Aircel"}]},
        {"c":[{"v":102},{"v":"Srini"}]},
        {"c":[{"v":103},{"v":"Tamil"}]},
        {"c":[{"v":104},{"v":"Thiyagu"}]},
        {"c":[{"v":105},{"v":"Vasan"}]},
        {"c":[{"v":107},{"v":"Senthil"}]},
        {"c":[{"v":108},{"v":"Sri"}]},
        {"c":[{"v":109},{"v":"Docomo"}]},
        {"c":[{"v":106},{"v":"Innodea"}]}
        ]
    }
    
    0 讨论(0)
  • 2021-01-05 20:58

    If the Data format should be like:

    data: [
        ["string", "string"], //first Column
        ["string1", number],
        ["string2", number],
        ["string3", number],
    ]
    

    then you can overcome this error.

    0 讨论(0)
  • 2021-01-05 21:01

    To extend on @sajal's accurate answer: Change the last line of your code from:

    echo json_encode($table);
    

    to:

    echo json_encode($table, JSON_NUMERIC_CHECK);
    

    This will tell json_encode to recognize numbers and abstain from wrapping them in quotes (Available since PHP 5.3.3.). http://php.net/manual/en/json.constants.php#constant.json-numeric-check

    0 讨论(0)
  • 2021-01-05 21:16

    In your drawChart() function, you are probably using google.visualization.arrayToDataTable, and this does not allow any nulls. Please use addColumn function explicitly

    0 讨论(0)
  • 2021-01-05 21:16

    On a BarChart, one of the columns (the second one) has to be a number. That can cause this error message.

    0 讨论(0)
提交回复
热议问题