|
Blogs
You might remember my earlier web log concerning the generation of bar codes via an Object-Oriented Graph creating library for PHP, called JPGraph. As you might remember, this library is also eminently suitable for creating all kinds of charts. Kit First initialise the scripts: <script type="text/javascript" src="/mochikit/MochiKit.js"></script> <script type="text/javascript" src="/plotkit/Base.js"></script> <script type="text/javascript" src="/plotkit/Layout.js"></script> <script type="text/javascript" src="/plotkit/Canvas.js"></script> <script type="text/javascript" src="/plotkit/SweetCanvas.js"></script>
Plotkit needs a canvas to draw on. See this web log for details on the tag. <div><canvas id="my_canvas" height="200" width="200"></canvas></div>
Create a chart, in this case a line chart var layout = new Layout("line");
Add the data to a set layout.addDataset("demo", [[10, 20], [15, 30] , [20, 40])
Things need to be calculated layout.evaluate(); The chart needs to be drawn on the canvas var canvas = MochiKit.DOM.getElement("my_canvas");
Link things together var plot = new PlotKit.SweetCanvasRenderer(canvas, layout);
And finally render stuff plot.render();
Flash
First is of all we define the chart <chart>
Then we provide the data <chart_data>
We define a row for the labels. <row>
The first cell is for labelling the other axis. <null/>
Then the labels follow <string>US</string> <string>India</string> …
And we end that row </row>
We start another one <row>
Since we don’t have axis in the pie chart, we don’t have labels for it <string/>
The data follows <number>100</number> <number>87</number> …
We end that row again </row>
And the data definition </chart_data>
The rest is configuration stuff <chart_grid_h thickness="0"/> <chart_pref rotation_x="60"/> <chart_rect x="175" y="0" width="350" height="350" positive_alpha="0"/>
I like the spinning option very much whereby the pie parts turn in the chart. <chart_transition type="spin" delay=".5" duration="0.75" order="category"/> <chart_type>3d pie</chart_type> <chart_value color="000000" alpha="65" font="arial" bold="true" size="10"
position="inside" prefix="" suffix="" decimals="0" separator=""
as_percentage="true"/>
<legend_label layout="horizontal" bullet="circle" font="arial" bold="true"
size="12" color="ffffff" alpha="85"/>
<legend_rect x="0" y="45" width="50" height="210" margin="10" fill_color="ffffff"
fill_alpha="10" line_color="000000" line_alpha="0" line_thickness="0"/>
<legend_transition type="dissolve" delay="0" duration="1"/> The colouring of the pie parts can be defined via: <series_color> <color>5D7CBA</color> <color>62509B</color> .. </series_color> Finally, we end the chart definition. </chart>
Conclusion As you can see, one can implement charts easily with little effort. “Why didn’t you use it in SDN World then?” you might ask. Despite being a perfect solution, the Flash chart didn’t have any javascript interface for passing the data. The data was already there and we wanted to avoid having to retrieve the data a second time via an XML feed and thereby putting unnecessary stress on the server. Therefore a home brew Flash (by Valery and his team) was the most suitable solution in our case.
The World According to SDN. Put yourself on the SND world map and earn 25 points. Spread the wor(l)d!
Eddy De Clercq is trying to discover the secrets of Business Intelligence at the Katholieke Universiteit Leuven (Belgium).
| |||||||||||||||||||||||||||||||||||||||||||||||