Menu

showlegend being ignored

Help
Matt Krevs
2007-09-17
2013-01-13
  • Matt Krevs

    Matt Krevs - 2007-09-17

    Hi all

    I'm using jfreechart 1.0.6 and cewolf 1.0 in my project and am having trouble getting the legend to not display

    My JSP is as follows

    <p>
    <cewolf:chart id="line" title="${player.person.fullName}" type="line" showlegend="false" xaxislabel="Match" yaxislabel="Runs" legendanchor="north">
        <cewolf:data><cewolf:producer id="stats"/></cewolf:data>
    </cewolf:chart>
    </p>
    <p>
    <cewolf:img chartid="line" renderer="/cewolf.chart" width="600" height="500" >
        <cewolf:map linkgeneratorid="stats" tooltipgeneratorid="stats"  />
    </cewolf:img>
    </p>

    cewolf and/or jfreechart seem be be ignoring showlegend="false" above, as the legend always displays. Also, if the legend always displays at the bottom of the page, ignoring the legendanchor="north" tag.

    Can anyone help me out here? Is showlegend and/or legendanchor broken when using cewolf 1.0 and/or jfreechart 1.0.6? Perhaps I should be looking at those post processor thingies instead?

     
    • bmatth

      bmatth - 2007-09-20

      Dealt with this a while back - JFreeChart 1.0.6 causes this because of some underlying legend changes.

      Going mostly from memory here, as I've lost these changes and no longer use cewolf.

      The problem is in AbstractChartDefinition:

          //removes first legend in the list
          public void removeLegend()
          {
            List subTitles = chart.getSubtitles();
            Iterator iter = subTitles.iterator();
            while (iter.hasNext())
            {
              Object o = iter.next();
              if (o instanceof LegendTitle)
              {
                iter.remove();
                break;  // remove this break to fix the showlegend problem
              }
            }
          }

      Think the fix is to remove the break statement, thus iterating through the entire list to remove all instances of LegendTitle.

      And while you're in AbstractChartDefinition, you might want to fix the east/west legend anchor behavior that seems backwards to me.

      In method getChart():
      ...
                  if (showLegend)
                  {

                      LegendTitle legend = this.getLegend();
                      switch (legendAnchor)
                      {
                          case ANCHOR_NORTH :
                              legend.setPosition(RectangleEdge.TOP);
                              break;
                          case ANCHOR_WEST :
                            legend.setPosition(RectangleEdge.RIGHT);
                              break;
                          case ANCHOR_EAST :
                            legend.setPosition(RectangleEdge.LEFT);
                              break;
                          default :
                            legend.setPosition(RectangleEdge.BOTTOM);
                      }
                  }
      ...

      reverse east/west to:
                          case ANCHOR_WEST :
                            legend.setPosition(RectangleEdge.LEFT);
                              break;
                          case ANCHOR_EAST :
                            legend.setPosition(RectangleEdge.RIGHT);
                              break;

      -Brian

       
    • y_masa

      y_masa - 2007-10-04
       

Log in to post a comment.