Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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>
like image 867
Harley Sugarman Avatar asked Jan 27 '26 08:01

Harley Sugarman


1 Answers

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!

like image 192
Harley Sugarman Avatar answered Jan 29 '26 22:01

Harley Sugarman