admin管理员组文章数量:1353653
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>
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>
Share
Improve this question
edited Dec 15, 2013 at 21:56
GEOCHET
21.3k15 gold badges77 silver badges99 bronze badges
asked Jul 16, 2012 at 23:23
Harley SugarmanHarley Sugarman
2931 gold badge3 silver badges10 bronze badges
1 Answer
Reset to default 4Never 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!
本文标签: javascriptGoogle Chart Data column(s) for axis 0 cannot be of type stringStack Overflow
版权声明:本文标题:javascript - Google Chart: Data column(s) for axis #0 cannot be of type string - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743933203a2564222.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论