Note that there are some explanatory texts on larger screens.

plurals
  1. POManipulating hash data for rChart - Ruby
    primarykey
    data
    text
    <p>I have some code that takes in a CSV file. I'm trying to use this information to create charts with <a href="http://amardaxini.github.io/rchart/" rel="nofollow">rChart</a> in Ruby. </p> <p>In my code I have CSV file loaded into a hash like the following:</p> <pre><code>CSV.new(open(url),:headers =&gt; true, :header_converters =&gt; :symbol, :converters =&gt; :all).each do |line| title = line.headers[0] points[line.fields[0]] = Hash[line.headers[1..-1].zip(line.fields[1..-1])] end </code></pre> <p>Later...</p> <pre><code>points.keys.sort.each do |key| puts "---" # added for clarification in SO example of each key points[key].each {|serie_name, point| puts "#{serie_name} = #{point}"} puts points[key].length # total number of series end </code></pre> <p>Outputs:</p> <pre><code>--- wmt_oracle = 68 irt_oracle = 44 wmt_sql = 20 irt_sql = 11 operations = 4 5 --- wmt_oracle = 23 irt_oracle = 44 wmt_sql = 160 irt_sql = 8 operations = 3 5 --- wmt_oracle = 66 irt_oracle = 224 wmt_sql = 48 irt_sql = 15 operations = 3 5 </code></pre> <p>In rChart datapoints for the stacked bar graph are added in the following way:</p> <pre><code>data.add_point([9,9,9,10,10,11,12,14,16,17,18,18,19,19,18,15,12,10,9],"Serie1"); data.add_point([10,11,11,12,12,13,14,15,17,19,22,24,23,23,22,20,18,16,14],"Serie2"); data.add_point([4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22],"Serie3"); . . . </code></pre> <p>For the above data I would need to have my data look like this:</p> <pre><code>data.add_point([68,23,66],"wmt_oracle"); data.add_point([44,44,224], "irt_oracle") data.add_point([20,160,48], "wmt_sql") data.add_point([11,8,15], "irt_sql") data.add_point([4,3,3], "operations") </code></pre> <p>It would be in the format <code>data.add_point(array_of_points, serie_name)</code> </p> <p>How can I get the data out of the hash into this format?</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.
 

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