Monday, May 3, 2010

Cewolf Axis

Dear bloggie,

Since I believe in give and take... Tis is a technical rant on how to configure Cewolf to render the chart axis according to ur needs.

<cewolf:chart
id="line"
title="Company Share Price"
type="timeseries"
xaxislabel="Date"
yaxislabel="Price">
<cewolf:data>
<cewolf:producer id="pageViews"/>
</cewolf:data>

<cewolf:chartpostprocessor id="dataColor" >
<cewolf:param name="0" value='<%= "#FF0000" %>'/>
</cewolf:chartpostprocessor>
</cewolf:chart>

To modify the chart setup, you need tis line
<cewolf:chartpostprocessor id="dataColor" >

U also need write an class that implements ChartPostProcessor and throw that object into ur session under the name "dataColor" (Up to u for name, just make sure match the id). Then u need implement the method processChart(Object obj, Map map). The obj paramter here can be cast into a JFreeChart object which allows u access to tons of setting objects.

For instance, if you wanna modify the y-axis's min and max values,

JFreeChart chart = (JFreeChart) obj;
XYPlot plot = (XYPlot) chart.getPlot();

NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setRange(1, 10);

This will make the stupid chart y-axis to be limited to 1 to 10.

And to enforce the interval so we don't have a random auto generated fugly y-axis value like 0.175 or 1.125

rangeAxis.setTickUnit(new NumberTickUnit(0.5));

Tis line of code will enforce the chart to follow a 0.5 scale. Meaning 1, 1.5, 2, 2.5, ..., 10.

I actually spent a couple of days hunting the www to find how to the stunts above.

And believe me, not an easy task with the lack of documentation and tutorial in Cewolf official website. Personally, I still don't like Cewolf as there is need to extends and implements quite a number of classes, not to mention understand the classes architecture. Compare that to Google Chart super clean API... Too bad the monkeys ruling China have bad blood with Google... Aiii.. sometimes I think programming isn't really the art of finding the best solution but rather navigate between crap like vendors power play, idiotic country IT policies, browsers refusal to follow standards and etc...

As House said "We become doctors to treat illness. Patients are why most doctors are miserable." Doesn't the same applies to our profession as well?

0 b*tchin: