How to limit the legends in a chart

  • Saravanakumar

    Saravanakumar - 2006-09-04

       I am using the below cewolf tag for generating the StackedHorizondalBar3D chart in my Application.
    Code in JSP,
    <cewolf:chart id="stackedBarID" type="stackedHorizontalBar3D" showlegend="true" xaxislabel="Devices" yaxislabel="Traffic Value(MB)">

    In PostProcessor class i used the below code to set the Font of the Legend,

    Font legendFont = new Font("Arial", Font.PLAIN, 9);
    StandardLegend standardlegend = (StandardLegend) ((JFreeChart) chart).getLegend();
       if( standardlegend != null )

    My Question here is, Can i set the Limit of the Legend for the Graph as "5/10" using the JFree chart API even though the data set contains more attributes.

    ie., Graph should not be affected and my only requirement is first 5/10 legend is enough to be shown in the Graph.

    Please post your valuable suggestion to me to solve my problem.


    • Zoltan Luspai

      Zoltan Luspai - 2006-09-04


      You should dig into jfreechart code for that.
      One possible way: for each JFreeChart there is one renderer class is assigned as default. Create a subclass of the default renderer of your chart type, and override the legend generator method, which may look like:
      public LegendItem getLegendItem(int datasetIndex, int series);
      It should return null for the unwanted legends. All these magic can go the a postprocessor, and set the new renderer to your chart: jfreechart.getPlot().setRenderer(new myrenderer());

      There might be other simpler ways too, I'd recommend to buy JFreeChart's demo/documentation; or search its forums; then the tricky code goes to postprocessors.


Log in to post a comment.

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

Sign up for the SourceForge newsletter:

No, thanks