How to call postproc.

Dennis
2005-03-14
2013-01-13
  • Dennis

    Dennis - 2005-03-14

    I can't find how I should call the post-processor...

    I thought it should be something like this;
    <cewolf:chart id="xy" title="design data chart" type="scatter" xaxislabel="dK" yaxislabel="da/dN">
        <cewolf:data>
            <cewolf:producer id="pageViews"/>
            <cewolf:chartpostprocessor id="pageViews"/>
        </cewolf:data>
    </cewolf:chart>

    but that generates a nullpointer...

    Can anybody tell me the right way to call it?

     
    • Zoltan Luspai

      Zoltan Luspai - 2005-03-14

      Here you refere to postprocessor as 'pageViews" so you should have an object which implements cewolf's ChartPostProcessor interface, and it is assumed to be found in any of the JSP scopes as 'pageView' (page/request/session/application).
      Here's an example from cewolfset_inc.jsp you'll find in the example web app:

      ChartPostProcessor meterPP = new ChartPostProcessor() {
         
              public void processChart(Object chart, Map params) {
                  MeterPlot plot = (MeterPlot) ((JFreeChart) chart).getPlot();
         
                  double min = 0;
                  double max = 260;
                  double val = 86;
                  double minCrit = 187;
                  double maxCrit = max;
                  double minWarn = 164;
                  double maxWarn = minCrit;
                  double maxNorm = minCrit;
                  double minNorm = min;
                 
                  plot.setRange(new Range(min, max));
                  plot.setNormalRange(new Range(minNorm, maxNorm));
                  plot.setWarningRange(new Range(minWarn, maxWarn));
                  plot.setCriticalRange(new Range(minCrit, maxCrit));
                 
                  plot.setUnits("km/h");
              }   
          };
          pageContext.setAttribute("meterRanges", meterPP);

       
    • Dennis

      Dennis - 2005-03-14

      Thanx for your reaction, but I still don't understand what I'm doing wrong...

      I have this peace of code;
      <cewolf:chart id="xy" title="design data chart" type="xy" xaxislabel="dK" yaxislabel="da/dN">
          <cewolf:data>
              <cewolf:producer id="pageViews"/>
              <cewolf:chartpostprocessor id="postproc"/>
          </cewolf:data>
      </cewolf:chart>

      and somewhere else in the same JSP I have this code;
      [code]
      ChartPostProcessor postprocessor = new ChartPostProcessor()
      {
          public void processChart(Object chart, Map params)
          {
              JFreeChart jfc = (JFreeChart) chart;
              XYPlot plot = (XYPlot) jfc.getPlot();
              java.awt.Color[] colors = new java.awt.Color[]
              {
                  java.awt.Color.YELLOW,
                  java.awt.Color.GRAY,
                  java.awt.Color.GREEN,
                  java.awt.Color.RED
              };
              for (int i = 0; i < 4; i++)
              {
                  XYItemRenderer renderer = plot.getRenderer(i);
                  renderer.setPaint(colors[i]);
              }
          }        
      };
      pageContext.setAttribute("postproc", postprocessor);[/code]

      I think this is almost the same as in the example, but still I get a NullPointer
      (PostProcessingException -> NullPointerException raised by post processor '.... etc. )

       
      • Zoltan Luspai

        Zoltan Luspai - 2005-03-14

        Well, some cognitive phylosophy says where is a NPE there is a null :-). So track your null!
        It would be easier if you paste in stack trace, but I guess the null is at here:
        renderer.setPaint(colors[i]); 
        , which probably means that XY chart does not have that many renderer (4).
        Btw; when you work on your chart design I'd suggest to write an app and put all the stuff together there (create the jfreechart and pull the postprocessor on it... That's way faster than working with an jsp app.
        Also look at cewolf examples -for cewolf usage-, and the jfree demo -for which chart to use and codes samples for postprocessor- that gives you lot of hints.

         
    • Dennis

      Dennis - 2005-03-15

      Thanx, you were right; the nullpointer is generated at renderer.setPaint... Although I know for sure there are 4 series in the chart, it can only find the first serie and after that it returns nullpointers...

      Why can't I adjust the other series??

       
      • Zoltan Luspai

        Zoltan Luspai - 2005-03-15

        Generally saying that depends on the type of the chart. For example if you look at the cewolf example's in the cewolfset_inc.jsp you will see this post processor:

        ChartPostProcessor dataColor = new ChartPostProcessor() {
                public void processChart(Object chart, Map params) {
                    CategoryPlot plot = (CategoryPlot) ((JFreeChart) chart).getPlot();
                    for (int i = 0; i < params.size(); i++) {
                        String colorStr = (String) params.get(String.valueOf(i));
                        plot.getRenderer().setSeriesPaint(i, java.awt.Color.decode(colorStr));
                    }
                }
            };

        ------------------
        That configures this chart:

        <cewolf:chart id="stackedHorizontalBar" title="StackedHorizontalBar" type="stackedHorizontalBar" xaxislabel="Fruit" yaxislabel="favorite">
            <cewolf:data>
                <cewolf:producer id="categoryData" />
            </cewolf:data>
            <cewolf:chartpostprocessor id="dataColor">
                <cewolf:param name="0" value='<%= "#FFFFAA" %>'/>
                <cewolf:param name="1" value='<%= "#AAFFAA" %>'/>
                <cewolf:param name="2" value='<%= "#FFAAFF" %>'/>
                <cewolf:param name="3" value='<%= "#FFAAAA" %>'/>
            </cewolf:chartpostprocessor>
        </cewolf:chart>

        ------------------

        So look at jfreechart source and its forums for details... Or buy the jfreechart book from their site.

         

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

Sign up for the SourceForge newsletter:





No, thanks