I recently installed a really nice set of charts and graphs called XML/SWF Charts using the Ziya plugin for Rails. The nice part is that it costs only $45 for your entire domain. This license fee will remove the link when you click on the chart (it currently goes to their website)
For the most part, the instructions in Ziya’s README were very good. I did run into a few snags, but they didn’t take me too long to figure out. Here’s a rundown. Hopefully this will make it even easier to implement Ziya and XML/SWF:
Under the “Steps” section of the the README:
1. If you get an error message when trying to install the Rails plugin on Windows, be sure to install the Window’s subversion client. This will install the command line svn client and add the subversion path to your environment variables. Be sure to open a new command prompt after installing the subversion client. This is the quickest way to get the latest version 0.12 of Ziya since they don’t make the latest code downloadable.
2. There’s an obvious typo in the following line
graph = Ziya::Charts::Bar.new( license, title, chart_id )
I changed it to the following to get something working quickly:
graph = Ziya::Charts::Line.new( nil, nil, "mychart" )
Here, "mychart"
is the name of the YAML stylesheet which will be:
public/charts/default/mychart.yml
3. My biggest mistake: You can not instantiate the Ziya object in the controller corresponding to the chart’s view. It needs to be in a separate controller. Otherwise, an XML file (instead of a chart) will be returned when that controller is invoked.
In other words, if the following view code is in line_chart.rhtml
file (note: here the ‘css_id’ is the id attribute for the <object> element that is rendered in the final HTML)
<%= ziya_chart( url_for( :controller => 'blee', :action => 'refresh_my_graph' ), :id => 'css_id', :bgcolor => "transparent", :width => 400, :height => 250 ) %>
Then you cannot put the following code in the line_chart
controller
def line_chartgraph = Ziya::Charts::Line.new( nil, nil, "mychart" )graph.add( :axis_category_text, [ "Dog", "Cat", "Rat"] )graph.add( :series, "Series A", [10, -20, 30] )render :xml => graph.to_xmlend
The controller name needs to be different. They used refresh_my_graph
as an example
4. The parameters passed into into the ziya_chart
helper in the line_chart.rhtml
file above apply to the canvas_bg property. These parameter apply to main canvas of the chart and cannot be specificed in the YAML file. The attributes for canvas_bg become part of the static html page.
The best way to specify attributes in the YAML stylesheet is to look at XML/SWF’s reference. It is very well documented and very understandble.
5. I was able to get their sample charting application working pretty quick. It’s the code for Ziya’s website. Download it by typing this at the command prompt (after you’ve done #1 above)
svn co svn://rubyforge.org/var/svn/liquidrail/samples/charting
After you download it, you will need to
a. Create a database called “ruby_dev” in your database server
b. Run
db:migrate
Thanks a lot to the folks at maani.us for providing such a nice and rich set of graphs and charts for next to nothing. And also thanks to Fernand Galiana and Delynn Berry for such a nicely written plugin to the Rails community!
That is interesting point of view, but I can`t agree at all.
Wow! Thank you! I constantly wanted to write on my blog something like that. Can I take a portion of your post to my blog?