Skip to content

Instantly share code, notes, and snippets.

@lenagroeger
Created August 28, 2012 18:38
Show Gist options
  • Save lenagroeger/3501903 to your computer and use it in GitHub Desktop.
Save lenagroeger/3501903 to your computer and use it in GitHub Desktop.
Faster CSV for bar graphs
require 'rubygems'
require 'fastercsv'
data = []
html = <<-HTML
HTML
FasterCSV.foreach("fda.csv", :headers => true) do |row|
data << row
end
data.each do |row|
el = <<-HTML
<div class="fda-graph-container">
<div class="fda-bar" style="height:#{((row["regular"].to_f))}%" data-year = "#{row["year"]}" data-specific = "#{row["regular"]}" data-total = "#{row["total"]}">
</div>
</div>
HTML
html << el
end
html << <<-HTML
HTML
File.open("fda.html", "w") do |f|
f.write html
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment