Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

Plot Label in Cewolf graphic bar

Help
Aninha
2006-04-03
2013-01-13
  • Aninha
    Aninha
    2006-04-03

    Hello People...

    I have plot the value above the graphic bar..

    I, m using the cewolf Smile

    Help-me Please..

    Thanks

     
    • MikGan
      MikGan
      2006-04-04

      in post processor

                  JFreeChart jChart = (JFreeChart)chart;
                  CategoryPlot plot = (CategoryPlot) jChart.getPlot();
                 
                  CategoryItemRenderer renderer = plot.getRenderer();
                  renderer.setBaseItemLabelGenerator(new LabelGenerator());
                  renderer.setItemLabelsVisible(true);

      and in labelGenerator

      public class LabelGenerator implements CategoryItemLabelGenerator
      {
          public String generateLabel(CategoryDataset dataset, int series, int category)
          {
              String result = null;
              final Number value = dataset.getValue(series, category);
              if (value != null)
              {
                  result = value.intValue() + ""; // could apply formatting here
              }
              return result;
         
          }
      }

       
      • Prak Sub
        Prak Sub
        2006-05-11

        This worked like a charm.  However, some bars' labels (values) are suppressed authormatically, may be by jFreeChart.   Is there a way to force display on top (outside) of each bars, instead of in top on the inside?

         
    • Aninha
      Aninha
      2006-04-04

      Thanks :)
      How i will implement in my code ??

      public class Producer implements DatasetProducer, Serializable
      {
          public Object produceDataset(Map map) throws DatasetProduceException
      {
              TimeSeriesCollection timeSeriesCollection = new TimeSeriesCollection();

              List list = (ArrayList)map.get( "dataset");
              for( Iterator iterator1 = list.iterator() ; iterator1.hasNext() ; )
      {
                  Parameter parameter = (Parameter)iterator1.next();

                  TimeSeries timeSeries = new TimeSeries( parameter.getName(), Minute.class );

                  Map parameters = parameter.getMap();
                  Set keys = parameters.keySet();
                  for( Iterator iterator2 = keys.iterator() ; iterator2.hasNext() ; ) {
                      Object key = iterator2.next();
                      Object value = parameters.get( key );
                      }
                  }

                  timeSeriesCollection.addSeries(timeSeries );
              }
              return timeSeriesCollection;
          }

      public boolean hasExpired(Map map, Date date)
      {
              return true;
      }

      public String getProducerId()
      {
              return "TimeSeries";
      }

      }

      Thanks People :)

       
    • Aninha
      Aninha
      2006-04-04

      Sorry People Code wrong :)
      this is correct
      public class BarProducer implements DatasetProducer,Serializable
      {
              public Object produceDataset(Map map) throws DatasetProduceException
              {

                      List list = (List) map.get("series");
                      DefaultCategoryDataset dataset = new DefaultCategoryDataset();

                      for (Iterator iterator1 = list.iterator(); iterator1.hasNext();) {
                              Serie serie = (Serie) iterator1.next();
                              Map items = serie.getMap();
                              Set keys = items.keySet();
                              for (Iterator iterator2 = keys.iterator(); iterator2.hasNext();) {
                                      Object key = iterator2.next();
                                      Object value = items.get(key);
                                      dataset.addValue((Number) value, serie.getName(), (String) key);
                              }
                      }
                      return dataset;
              }

              public boolean hasExpired(Map arg0, Date arg1) {
                      return (System.currentTimeMillis() - arg1.getTime()) > 5000;
              }

              public String getProducerId() {
                      return "DatasetProducer";
              }

          public String generateToolTip(CategoryDataset dataset, int series, int index) {
              return String.valueOf(dataset.getValue(series, index));
          }
      }

      How i will implement this in my code??

      :)

      Thanks

       
    • MikGan
      MikGan
      2006-04-04

      The code I put up goes in your post processor. Its another class used for UI side operations on your graphs. Have a look around in the post processor forum.

      the post processor is invoked through your JSP like this

      <cewolf:chart id="line" type="horizontalBar" title="ABC" showlegend="true">
          <cewolf:data>
              <cewolf:producer id="producer" usecache="false"/>
          </cewolf:data>
          <cewolf:chartpostprocessor id="postProcessor"/>
      </cewolf:chart>

       
    • MikGan
      MikGan
      2006-04-04

      obviously with a bit of a <jsp: usebean up the top...

       
    • Aninha
      Aninha
      2006-04-04

      I try implement in my class but i dont obtive sucess :(

      public class BarProducer implements DatasetProducer,Serializable,CategoryToolTipGenerator
      {
          public Object produceDataset(Map map) throws DatasetProduceException
          {
             
              List list = (List) map.get("series");
              DefaultCategoryDataset dataset = new DefaultCategoryDataset();

              for (Iterator iterator1 = list.iterator(); iterator1.hasNext();) {
                  Serie serie = (Serie) iterator1.next();
                  Map items = serie.getMap();
                  Set keys = items.keySet();
                  for (Iterator iterator2 = keys.iterator(); iterator2.hasNext();) {
                      Object key = iterator2.next();
                      Object value = items.get(key);
                      dataset.addValue((Number) value, serie.getName(), (String) key);
                  }
             
              }
             
              return dataset;
          }

          public boolean hasExpired(Map arg0, Date arg1) {
              return (System.currentTimeMillis() - arg1.getTime()) > 5000;
          }

          public String getProducerId() {
              return "DatasetProducer";
          }
         

          public String generateToolTip(CategoryDataset dataset, int series, int index) {
              return String.valueOf(dataset.getValue(series, index));
          }
        
          public void processChart(Object obj, Map map)
          {
            
              JFreeChart chart = (JFreeChart)obj;
             
              Font fontSubTitle = new Font( null, Font.PLAIN, 13 );
                
              CategoryPlot plot = (CategoryPlot) chart.getPlot();
              
              CategoryItemRenderer renderer = plot.getRenderer();
              renderer.setBaseItemLabelGenerator(new generateLabel()); <----- wrong this cannot be resolved the type
              renderer.setItemLabelsVisible(true);
             
             
          }
         
          public String generateLabel(CategoryDataset dataset, int series, int category) 
          {
          String result = null;
          final Number value = dataset.getValue(series, category);
          if (value != null) 
          {
          result = value.intValue() + ""; // could apply formatting here
          }
          return result;
          
          }

      }

      im my JSP is :
      <jsp:useBean id="bar" scope="page" class="util.BarProducer" />

      <cewolf:chart id="chart" title="${title}" type="verticalbar"
          xaxislabel="Test" yaxislabel="Data" showlegend="true" >
          <cewolf:colorpaint color="#FFFFFF" />
      <cewolf:gradientpaint>
      <cewolf:point x="0" y="0" color="#FBFBFB" />
      <cewolf:point x="350" y="0" color="#1A6C9B" />
      </cewolf:gradientpaint>
          <cewolf:data>
              <cewolf:producer id="bar">
                      <cewolf:param name="series" value="${series}" />
              </cewolf:producer>
          </cewolf:data>
         
      </cewolf:chart>
      <cewolf:img chartid="chart" renderer="/cewolf" width="400" height="300" align="center" >

      mikgan help-me please!! :)

      Thanks for help!!

       
      • In brief, everything seems to be right but one detail:

        public class BarProducer implements
        DatasetProducer,Serializable,CategoryToolTipGenerator
        {

        You forgot to put ChartPostProcessor, so your method  processChart is not implementing any interface and it wont be call.

        Good luck.

         
    • MikGan
      MikGan
      2006-04-05

      okay your way off, look the generateLabel needs to go into a CategoryItemLabelGenerator, and that is used from within a ChartPostProcessor and all that is fired from the JSP using the <cewolf:chartpostprocessor> tag.

      So step 1, make a new class and have it extend ChartPostProcessor, in therre there needs to be a method:

      public void processChart(Object chart, Map params)

      and that will create a class that extends CategoryItemLabelGenerator, so make a class that does that, and in there override the method called

      public String generateLabel(CategoryDataset dataset, int series, int category)

      an in there put the result = value.intValue() + ""; code slab.

      after that, put the JSP tag in and point it to the right class (your postProcessor) and away it should go.

       
    • Aninha
      Aninha
      2006-04-06

      Help-me.. how I do this?? :(
      I don't   know :(

      Thanks

       
    • Aninha
      Aninha
      2006-04-09

      Nothing?? :)
      Please people..help-me :)

       
    • Aninha
      Aninha
      2006-04-20

      People.. please.. help-me

       
    • MikGan
      MikGan
      2006-05-17

      What values are you meaning? zero values? or are there certian values that always dont show?

      There is a 'bug' in Jfreecharts that means that some high values may appear to be cliped because they lie outside the canvas of the image, the fix for that was just to extend the axis range by a factor to make them visible, I used 10% and everything fits now.

       
    • Damien Ng
      Damien Ng
      2007-05-07

      MikGan:
      "...the fix for that was just to extend the axis range by a factor to make them visible, I used 10% and everything fits now. "

      How do I extend the axis range?