| Path: | README |
| Last Update: | Mon Nov 05 08:58:14 -0700 2007 |
ZiYa Plugin
Contributors:
Fernand Galiana (fernand.galiana@gmail.com) - Conception and Initial implementation Delynn Berry ( delynn@gmail.com) - Conception and implementation
ZiYa allows you to easily display graphs in your rails application by leveraging SWF Charts (www.maani.us/xml_charts/index.php). This plugin bundles version 4.5 of the flash library. Incorporating flash graphs in your app relieves the server by allowing for delegating graph rendering to the client side. Using this plugin, you will be able to easily create great looking charts for your application. You will also be able to use the charts has a navigation scheme by embedding various link in the chart components thus bring to the table an ideal scheme for reporting and dashboard like applications. Your managers will love you for it !!
Checkout the demo: http://ziya.liquidrail.com
Video : http://www.youtube.com/watch?v=axIMmMHdXzo
Documentation : http://ziya.liquidrail.com/rdoc
Forum : http://groups.google.com/group/ziya-plugin
A Sample charting rails application can be found here:
svn co svn://rubyforge.org/var/svn/liquidrail/samples/charting
Additionaly there is a sample application illustrating composite charts
svn co svn://rubyforge.org/var/svn/liquidrail/samples/composite
Just add mongrel ;-)
svn co svn://rubyforge.org/var/svn/liquidrail/samples/printing
You must have a valid XML/SWF charts to enable this feature. The printing story behind XML/SWF charts is less than ideal. We are pushing on the authors to obtain corrections and patches. If you are a registered user, we encourage you to do the same. Here is a matrix of printing scenarios we have compiled. We will need your help validating and completing this data going forward so please pipe in if you see different results.
Browser versions : Firefox 2.0.0.4, Safari 3.0
Printing was surfaced via a browser page print (P) or print button (PB)
Platform Firefox(PB) Firefox(P) Safari(PB) Safari(P) IE6(BP) IE6(P) IE7(BP) IE7(P)
Windows XP Yes Yes X X Yes Yes Yes Yes
Mac OSX Yes No Yes Yes X X X X
Printing and hidden legends: One more issue on printing. The standard trick for hidden legends was to move the legend off the screen by setting the x,y coordinated to negative values. Unfortunately this won‘t work for printing. You will need to set the width, height and font-size to zero in order to hide the legend on screen and on print medias.
def load_chart
chart = Ziya::Charts::Bar.new
....
response.headers["Cache-Control"] = "no-cache"
render :xml => chart.to_xml
end
- Fixed typo in base chart file - Thanks Lori !
- Added Composite chart support. Please take a look at the composite chart sample application for information: svn co svn://rubyforge.org/var/svn/liquidrail/samples/charting - Added James Hunt patch to correct the object and embed tag generation in the ziya_helper. Thanks James !!
- Fix issue with series name containing a '%' character. Eliminated the dependency with sprintf and the series name.
NOTE: XML/SWF charts are free of charge unless you need to use special features such as embedded links and printing. The package cost $45 per domain and is well worth the investment.
> ruby script/plugin install svn://rubyforge.org/var/svn/liquidrail/plugins/ziya/trunk
require ‘ziya’ # <— Pull in ZiYa
class BleeController < ApplicationController
include Ziya # <---- Include ZiYa Charts
def refresh_my_graph
graph = Ziya::Charts::Bar.new( license, title, chart_id )
graph.add( :axis_category_text, [ "Dog", "Cat", "Rat"] )
graph.add( :series, "Series A", [10, -20, 30] )
render :xml => graph.to_xml
end
end
The code above will create a bar chart and generate the necessary xml to pass to the client for rendering. The chart constructor can take the xml/swf charts license, a chart name and a chart id used to lookup the chart YAML style-sheet. If no chart_id is specified the YAML file named after the chart class name will be used. So in this case YAML styles will be loaded as follows:
base_chart.yml
bar_chart.yml
chart_id.yml
Preferences will be overridden by the outermost YAML file.
Sorry no idiot proof validation as of yet, so pay attention to these…
The add call can have the following options:
:axis_category_text Specifies an array of value that will be displayed on the x or y axis depending on the type of chart.
Example: chart.add( :axis_category_text, [‘Dog’, ‘Cat’] )
:series Specifies an array representing the data points to draw the chart from. The next argument is the series name to will be displayed in the chart legends. Next is an array of data points. Optionally you can override the default chart labels by specifying an array of label values. You can add multiple :series tags for a given chart.
Example: chart.add( :series, "Series A", [10, 60, 90], [‘Temp lo’, ‘Temp Avg’, ‘Temp Hi’] )
:axis_value_text This option allows you to override the x/y axis ticks depending on the chart type. This should be an array of strings that will label one of the chart axis.
:user_data You can pass user defined params to the chart stylesheet using this argument. You will be able to access these values from the chart style sheets via @options hash which allows you to provide more dynamic styling based on some given state.
Example: graph.add( :user_data, :fred, "Fred" )
Then in you chart style sheet YAML file you can access :fred
<%=comp series_color %>
<% if @options[:fred] == "Fred" %>
colors: ffffff,000000
<% else %>
colors: ff00ff,aabbcc
<% end %>
This gives you access to infinite possibilities to change the look and feel of any charts based on certain state.
Additionally you can define methods in a file called helpers/ziya_helper.rb as follows:
module ZiyaHelpers
def red
"ff0000"
end
end
Then in you style file you can access the helper method as follows:
<%=comp series_color %>
colors: <%=red%>,000000
In your view template you would specify the following:
<%= ziya_chart( url_for( :controller => 'blee', :action => 'refresh_my_graph' ),
:id => 'my_chart', :bgcolor => "transparent", :width => 400, :height => 250 ) %>
For example, say you have a bar chart and want to override the default bar colors. You will need to perform the following steps:
my_bar_chart = Ziya::Charts::Bar.new( license, nil, "my_bar" )
<%=chart :bar_chart %>
<%=comp :series_color %>
colors: ff0000,00ff00
Save and refresh your browser and you should now see your new colors…
You can create a new themes directory under your public/chart/themes directory. Add the various YAML chart styles into that directory. To access your new theme you will need to add the following line to your controller:
class BleeController < ApplicationController
ziya_theme 'my_theme' ...
end