stefsava / google-charts-on-rails

Automatically exported from code.google.com/p/google-charts-on-rails
MIT License
0 stars 0 forks source link

[PATCH] Added support for line charts (chxt and chxl) #5

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I needed to use the Google Chart API in Rails today and I happened across your 
project here.  The 
code was great; very well written.  Looking through your documentation and 
code, it seems as 
though it was written primarily for pie charts but I just need it for simple 
line charts.

I started poking around in the code and was able to modify it to fit my needs.  
It wasn't exactly a 
small change, but I think it came out well.

The first thing I needed was the ability to specify the required axes via chxt 
and the 
corresponding labels using chxl.  With pie charts, a simple array of labels is 
adequate, but not 
with line charts.  So I changed how labels are passed to the methods and while 
I was at it, I also 
simplified how data is entered, too.

The current sample:
GoogleChart.pie(['1997',10],['1998',20],['1999',40],['2000',30])

With my changes:
GoogleChart.pie(:data => [ 10, 20, 40, 30 ], :labels => [ '1997', '1998', 
'1999', '2000' ])

Creating a line chart looks like this:
GoogleChart.line(:data => [10, 20, 40, 30], :labels => { :x => [ 'Jan', 'Feb', 
'Mar', 'Apr' ], :y => [ '', 
'25', '50', '75', '100' ] })

Which produces:
chxt=x,y
chxl=0:|Jan|Feb|Mar|Apr|1:||25|50|75|100

It's definitely not perfect and I'd be interested in working with you guys to 
implement and perfect 
other charting types.

Original issue reported on code.google.com by lmarbur...@gmail.com on 20 Feb 2008 at 12:15

Attachments:

GoogleCodeExporter commented 9 years ago

Original comment by bragha...@gmail.com on 21 Feb 2008 at 10:00

GoogleCodeExporter commented 9 years ago
lmarburger: Thank you for the patch, I wonder if we should do such a drastic 
change.
I do not really know how many are actually using this plugin yet. I am 
debating, if
we should not discard the old way of passing args and also implement your new
descriptive args. What you say?

It is not hard to have them both working together.

PS: There are few other changes to the code today in the trunk. I do not think 
they
will affect your patch, can you please update. Thanks. 

Original comment by bragha...@gmail.com on 21 Feb 2008 at 10:12

GoogleCodeExporter commented 9 years ago
I completely understand with regards to your apprehension to making such a 
change to the project.  I made my 
changes pretty much in a vacuum.  I needed specific functionality and I made 
them for myself and not 
necessarily with the project in mind.

I don't know what the vision is for the project and what the end goal should be 
so my modifications were purely 
selfish in nature.  I figured since I made the changes and the code base is 
pretty light, I might as well submit it as 
a patch.

Original comment by lmarbur...@gmail.com on 21 Feb 2008 at 2:53

GoogleCodeExporter commented 9 years ago
sure, nothing stops us to get to use your changes. If you would like to 
re-think the
patch, you are most welcome to do so. Or else I will implement you requirement
tomorrow. Thanks for raising the issue anyway.

Original comment by bragha...@gmail.com on 21 Feb 2008 at 3:01

GoogleCodeExporter commented 9 years ago
I have been trying to use this library and ran into the same problem addressed 
by
this patch. The module needs a way to support xy line charts, and currently 
doesn't
produce xy arrays in the format required by the api. The api requires
x[0],x[1],x[2]|y[0],y[1],y[2] and the current tool joins them all with ','s. 

I like the technique in the patch of being able to pass in the x and y data 
arrays on
one line and the labels on another. Can I download this patch in ruby someway? 

Original comment by spend...@gmail.com on 22 Mar 2008 at 4:08

GoogleCodeExporter commented 9 years ago
spendres,

The patch submitted by Imarburger is available, just click on the link and 
apply. For
more help in applying a patch, please refer to SVN.  I am still working on
implementing his patch. Unfortunately it had taken longer than I expected, as I 
have
to keep a backwards compatibility. 

Original comment by bragha...@gmail.com on 22 Mar 2008 at 10:40

GoogleCodeExporter commented 9 years ago
Hey guys

This patch seems to be working great! Kudos to Imarburger.
Anyway, I've created a patch for the patched version of google_chart.rb to 
handle
support for bar width and spacing. I've also added a new line to the join in 
case
anyone place an integer in there.
Anyway, here it goes, hope you guys find it useful.

Original comment by ebell...@gmail.com on 26 May 2008 at 9:32

Attachments: