1

I am following instructions in this page

http://googlecharts.rubyforge.org/

Here is my code

Gchart.line(:data => data,:axis_with_labels => ["x"],:axis_labels => ["0","15","30","45","60"], :format => 'file', :filename => "/path/to/file/#{stamp}.png")  

I expect a chart with labels in x axis but I got this chart

enter image description here

Something I am missing in here?

UPDATE:

I fixed this issue with another extra pair of [] like this

Gchart.line(:data => data,:axis_with_labels => ["x"],:axis_labels => [["0","15","30","45","60"]], :format => 'file', :filename => "/path/to/file/#{stamp}.png") 
icn
  • 17,126
  • 39
  • 105
  • 141

2 Answers2

1

The example on the documentation has the same problem so it seems like a gem issue. I didn't feel like digging through the source but if you're not married to the gem, you can always try gchart which can be installed by gem install gchart.

Here is how you would do the same thing with gchart.

require 'gchart'

chart = GChart.line do |g| 
  g.data = data

  g.axis(:bottom) do |a| 
    a.labels = ["0", "15", "30", "45", "60"]
  end 

  g.axis(:bottom) do |a| 
    a.labels = ["x"]
    a.label_positions = [50]
  end 

  g.write("/path/to/file/#{stamp}.png")
end
sunnyrjuneja
  • 6,033
  • 2
  • 32
  • 51
  • Thanks. I install 'gem install gchart' and tried the code I got this error. "\x89" from ASCII-8BIT to UTF-8 at g.write() line. Any idea? – icn Nov 01 '12 at 22:32
  • Did you you pass any arguments to g.write? Can you put exactly what you pass in g.write? – sunnyrjuneja Nov 02 '12 at 01:12
  • Check http://stackoverflow.com/questions/10177674/how-do-i-embed-an-uploaded-binary-files-ascii-8bit-in-an-xml-utf-8 – sunnyrjuneja Nov 02 '12 at 03:16
0

I solved this by switching to the vertical bar delimited syntax. For example:

x_axis_labels = [1, 2, 3]
Gchart.line(:axis_labels => [x_axis_labels.join('|')], ...)

Probably a bug in the gem.