mattetti / googlecharts

Ruby Google Chart API
http://mattetti.github.com/googlecharts/
MIT License
699 stars 108 forks source link

axis_range for y-axis while using x-axis labels #4

Closed ghazel closed 14 years ago

ghazel commented 15 years ago

I'm trying to draw a vertical bar graph with a manually-labelled x-axis and an automatically labelled y-axis. This is possible, and here is the correct url:

http://chart.apis.google.com/chart?chs=300x200&chxr=0,0,5&chxt=y,x&chd=s:AM9&cht=bvs&chxl=1:%7Cfoo%7Cbar%7Cqux

Gcharts does not seem to allow this, however. Here's the closest I can get:

does not display y-axis labels: chart = Gchart.bar(:data => [0, 1, 5], :axis_with_labels => 'x', :axis_labels => [['foo', 'bar', 'qux']])

=> http://chart.apis.google.com/chart?chs=300x200&chxr=0,0,5&chxt=x&chd=s:AM9&cht=bvs&chxl=0:%7Cfoo%7Cbar%7Cqux

incorrect y-axis range: chart = Gchart.bar(:data => [0, 1, 5], :axis_with_labels => 'x,y', :axis_labels => [['foo', 'bar', 'qux']])

=> http://chart.apis.google.com/chart?chs=300x200&chxr=0,0,5&chxt=x,y&chd=s:AM9&cht=bvs&chxl=0:%7Cfoo%7Cbar%7Cqux

does not display y-axis labels: chart = Gchart.bar(:data => [0, 1, 5], :axis_with_labels => 'y,x', :axis_labels => [nil, ['foo', 'bar', 'qux']])

=> http://chart.apis.google.com/chart?chs=300x200&chxr=0,0,5&chxt=y,x&chd=s:AM9&cht=bvs&chxl=0:%7C%7C1:%7Cfoo%7Cbar%7Cqux

So maybe axis_labels should optionally take a Hash, so I can specify the labels for axis 1 without it inserting a blank label list for axis 0?

Also, maybe Gchart#full_data_range should pay attention to axis ordering from :axis_with_labels. It currently inserts the axis_range for axis 0, even if they have been swapped.

ghazel commented 15 years ago

The Hash method is implemented http://github.com/ghazel/googlecharts/tree I chose to leave axis_with_labels alone, since the API likes to leave data and axis separate.

mattetti commented 14 years ago

This is now fixed thanks to ghazel's help, update to 1.5 to have this feature working