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

24,166

Never mind - I solved it. The problem was that I had wiped the production database a few days ago, so when I went to get the plot data, it wouldn't fetch anything. This caused the error, since the array would then only look like:

["Date", "Value"]

Hence the string error.

Sorry!

Share:
24,166
Harley Sugarman
Author by

Harley Sugarman

Updated on December 16, 2020

Comments

  • Harley Sugarman
    Harley Sugarman almost 3 years

    I'm having a really weird problem with a Google Chart that I'm displaying on my webpage. When I run the code locally on my Mac, everything works, and the graph displays with no error.

    However, when I run the same app on the AWS server I'm testing with, I get the following error message and no graph:

    Data column(s) for axis #0 cannot be of type string
    

    The app is written in ruby-on-rails, and the relevant code is pasted below:

    (In the page's controller)

    relevantEntries = getDataFromDB
    @graphData = Array.new
    @graphData << ["Date", "Value"]
    relevantEntries.each do |entry|
      @graphData << [entry.created.strftime(format="%-m/%-d"), entry.value]
    end
    

    (In the page's view)

      google.load('visualization', '1.0', {'packages':['corechart']});
      google.setOnLoadCallback(ChartMaker);
    
      function ChartMaker(chartDiv) {
        // Create the data table.
        var data = google.visualization.arrayToDataTable(<%= @graphData.to_json.html_safe %>);
        // Set chart options
        var options = {/* some options */};
        // Instantiate and draw chart, passing in the options.
        var chart = new google.visualization.LineChart(document.getElementById(chartDiv));
        chart.draw(data, options);
      }
    
    </script>