I’m having an error when publishing my rails app to Heroku with Highcharts (error 14). In development it all works fine, and the values aren’t transformed into strings.
Basically, when my view is loaded on Heroku, i get the following code :
<script type="text/javascript" charset="UTF-8">
$(function () {
var chart;
$(document).ready(function() {
chart = new Highcharts.Chart({
chart: {
renderTo: 'visualization',
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false
},
title: {
text: 'Receipts by Gender'
},
tooltip: {
formatter: function() {
return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %';
}
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: false
},
showInLegend: true
}
},
series: [{
type: 'pie',
name: 'Receipts by gender',
data: [["M", "432854518.0"]]
}]
});
});
});
</script>
If we look at series.data, we will see [[“M”, “432854518.0”]], and here we have the problem. The value on the right should be a float or at least an integer.
My controller :
@pie_gender_total = Receipt.group_by_gender_pie(current_user, :total)
@pie_gender = @pie_gender_total
My view :
<script type="text/javascript" charset="UTF-8">
$(function () {
var chart;
$(document).ready(function() {
chart = new Highcharts.Chart({
...
series: [{
...
data: <%=raw @pie_gender %>
}]
});
});
});
</script>
And my model method :
def self.group_by_gender_pie(user, dim, begin_date=nil, end_date=nil)
arr=[]
self.group_by_gender(user).each do |item| arr.push([item.gender, dim == :count ? item.number_of_receipts : item.total]) end
arr
end
Any ideas on why the same solution works in development, but not so for my heroku environment ? And workarounds ?
Finally, i found that the problem could be tracked down to the model.
Here is the solution (basically convert the numbers to float) :
I still don’t understand why the different behaviour between development and heroku though.