Closed luizkowalski closed 12 years ago
You're nearly there with removing the quotes from value
-- Morris.js requires numerical values in that field.
Try using a helper (or maybe a decorator?) to map #to_i against the values.
I'm still searching for a way to do this... Any piece of code?
Something like the following, perhaps?
# in application_helper.rb
def donut_json
@result_donut.map { |x| {:label => x[:label], :value => x[:value].to_i} }.to_json.to_s.html_safe
end
.. and then, in your view
<script>
Morris.Donut({
element: 'donut',
data: <%= donut_json %>
});
</script>
Disclaimer: this is quick and dirty code, so you may want to tidy/reorganise it as you see fit.
changed to this:
<%= @donut.map { |x| {:label => x['label'], :value => x['value'].to_i} }.to_json.to_s.html_safe %>
Worked...now, as I'm working with worked and business hours, would be nice if Donuts graphics could have a formatter to the values, because I'm getting the values in seconds, but this should be another issue :)
I'm closing this one
I have this JSON
When I try to use it on donut chart, like this
the output is rendered like this picture Imgur
if I remove the double quotes on
value
, it works, but this data comes from a sql which I convert to JSON