Example to Implement ChartPost Processor

2005-09-01
2013-01-13
  • Adnan Siddiqi

    Adnan Siddiqi - 2005-09-01

    I want to set range in Integer format on Y-axis,somebody asked me to use PostProcessor for this task,i didnt find any example to implement the PostProcessor method and calling in JSP,

    please please Guide Me..

     
    • rionheart

      rionheart - 2005-09-01

      Hi again,

      Well, you'll need some understanding of using Java, otherwise you're going to have difficulty.  Assuming that is not a problem, read on.

      First, you'll need to create a Java class that implements the de.laures.cewolf.ChartPostProcessor interface, which basically requires a processChart() method.  A simple example would be:

      import java.util.Map;
      import org.jfree.chart.plot.XYPlot;
      import org.jfree.chart.axis.NumberAxis;
      import org.jfree.chart.JFreeChart;
      import de.laures.cewolf.ChartPostProcessor;

      public class MyChartPostProcessor implements ChartPostProcessor {
          public void processChart(Object chart, Map params) {
              XYPlot plot = (XYPlot)((JFreeChart) chart).getPlot();
              NumberAxis yAxis = (NumberAxis)plot.getRangeAxis();
              yAxis.setLowerBound( (double)0 );
              yAxis.setUpperBound( (double)100 );
              ((JFreeChart)chart).setTitle("Post Processed Chart");
          }   
      };

      Note that depending on the type of chart you're creating, XYPlot and NumberAxis might not be appropriate.  Start looking into the the JFreeChart, XYPlot, Plot, NumberAxis and ValueAxis classes for ways to manipulate your charts.

      Anyway, compile your class and put it in your 'classes' directory.  Then in the JSP, include something like

      <%
      MyChartPostProcessor chartPP = new MyChartPostProcessor();
      pageContext.setAttribute("myChartPP", chartPP);
      %>

      You can also just include the entire class inline as part of your JSP, but that's messy in my opinion... lots of examples of that in these forums and in the example apps if you that's how you want to do it.

      Lastly, you need to include a <cewolf:chartpostprocessor> tag within your <cewolf:chart> tag.  For instance:

      <cewolf:chart
          id="mychart"
          type="timeseries"
          antialias="true"
          showlegend="true"
          yaxislabel="units">
          <cewolf:data>
              <%-- however you create your data --%>
          </cewolf:data>
          <cewolf:chartpostprocessor id="myChartPP">
              <%-- optional <cewolf:param> tags --%>
          </cewolf:chartpostprocessor>   
      </cewolf:chart>

       
  • Diptesh Chakraborty

    I have used the above code of chart post processor but it seems that the chart processor is not being called,,,

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks