All,
I have a csv file with 2 columns.I have to plot a graph based on this data. Column1(X axis) is simple incrementing numbers and column 2 has random positive integers(Y axis). A sample data looks like this
1 95
2 95
3 95
4 85
5 81
6 81
7 84
8 92
9 85
I have to read the contents of the file and display it in a graph. I'm an absolute newb in Ruby. Here is the code I'm working on (not mine):
data = [] fields = [] csv_data = {} File.open(CSV_FILENAME, "r").each_line do |line| line = line.strip.split(',') csv_data[line.first.to_s] = line.last end csv_data.each do |row| content = row.first log "Creating data point: #{content}" fields << content data << row.last.to_i end The output I see in terminal is totally different. Here is the output I see:
Creating data point: 6
Creating data point: 7
Creating data point: 8
Creating data point: 9
Creating data point: 1
Creating data point: 2
etc.
As result the graph is also not correct. I want the output to be in this form:
Creating data point: 1
Creating data point: 2
Creating data point: 3
etc.
What's wrong in this piece of code?