Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is the answer just in case if it helps out anyone. This is the example with dynamic data. <a href="http://www.highcharts.com/demo/waterfall" rel="nofollow">http://www.highcharts.com/demo/waterfall</a> .In the controller file </p> <pre><code>class GraphsController &lt; ApplicationController def index defaults = [:name=&gt;'Positive Balance', :isIntermediateSum=&gt;'true', :color=&gt;'Highcharts.getOptions().colors[1]'] #array for positive balance which would automatically be calculated once we pass the correct values in the json format defaults_final = [:name=&gt;'Balance', :isSum=&gt;'true', :color=&gt;'Highcharts.getOptions().colors[1]'] #array for final balance positivegraph = Graph.all(:conditions =&gt;'y &gt; 0') # for the positive values negativegraph = Graph.all(:conditions =&gt;'y &lt; 0') # for the negative values positive_graph = positivegraph.collect{|graph| {:name=&gt;graph.name, :y=&gt;graph.y}} # form an array of positive values negative_graph = negativegraph.collect{|graph| {:name=&gt;graph.name, :y=&gt;graph.y}} # form an array of negative values @user_hash_array = positive_graph.concat(defaults) #concat arrays successively @user_hash_array = @user_hash_array.concat(negative_graph) @user_hash_array = @user_hash_array.concat(defaults_final).to_json end end </code></pre> <p>In the view file I have</p> <pre><code>&lt;!DOCTYPE HTML&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt; &lt;%= javascript_include_tag :defaults %&gt; &lt;%= javascript_include_tag 'jquery.min' %&gt; &lt;%= javascript_include_tag 'highcharts' %&gt; &lt;!--[if IE]&gt; &lt;%= javascript_include_tag 'excanvas.compiled' %&gt; &lt;![endif]--&gt; &lt;%= javascript_include_tag 'highcharts-more' %&gt; &lt;%= javascript_include_tag 'exporting' %&gt; &lt;title&gt;Highcharts Example&lt;/title&gt; &lt;script type="text/javascript"&gt; $(function () { $('#container').highcharts({ chart: { type: 'waterfall' }, title: { text: 'Highcharts Waterfall' }, xAxis: { type: 'category' }, yAxis: { title: { text: 'USD' } }, legend: { enabled: false }, tooltip: { pointFormat: '&lt;b&gt;${point.y:,.2f}&lt;/b&gt; USD' }, series: [{ upColor: Highcharts.getOptions().colors[2], color: Highcharts.getOptions().colors[3], data: &lt;%= raw @user_hash_array %&gt; , dataLabels: { enabled: true, formatter: function () { return Highcharts.numberFormat(this.y / 1000, 0, ',') + 'k'; }, style: { color: '#FFFFFF', fontWeight: 'bold', textShadow: '0px 0px 3px black' } }, pointPadding: 0 }] }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="container" style="min-width: 310px; max-width: 600px; height: 400px; margin: 0 auto"&gt;&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>In the database I have two fields 1 is the <strong>name</strong> field and the other field is <strong>y</strong> which has the integer values.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload