Change order of LegendItems via Postprocessor

  • Markus Daniel

    Markus Daniel - 2010-06-03

    Hi everyone,
    I tried to the order of my LegendItems in a CategoryPlot via Postprocessor.
    I have overridden the getLegentItems()-Method in my Postprocessor owned CategoryPlot, but I can not find any possibility to set this Plot into the Chart.

    Is there any possibility to do so?



  • Ulf Dittmer

    Ulf Dittmer - 2010-06-25

    No, you can't set a different Plot object - you need to work with the one that already exists (which you can get at via chart.getPlot()). Then you need to cast that Plot object to the specific Plot subtype that you're working with, after which you can get at the Renderer, and through that at the LegendItem objects - which you can then alter to your heart's content.

  • Markus Daniel

    Markus Daniel - 2010-06-26


    thanks a lot for the answer..

    I tried to get the LegendItemCollection plot.getRenderer().getLegendItems(); (plot is a CategoryPlot),
    iterate over the collection LegendItem item = (LegendItem);
    and to change the color of the label.

    I tried to use legendItem.setLabelPaint(Paint paint)
    but it does not change anything.

    What is wrong on my approache?

    I am using jfreechart 1.0.13 and cewolf 1.0.0,
    I tried to change the color of the legendItemLabel via PostProcessor.

    Kind regards,


  • Ulf Dittmer

    Ulf Dittmer - 2010-06-27

    Here's a postprocessor that changes the label colors on a category plot; I've verified that it works fine. (As an aside, you should use the cewolf distribution from, not the one downloadable here).

    public class LegendItemPostProcessor implements ChartPostProcessor, Serializable
        public void processChart (Object chart, Map params) {
            CategoryPlot plot = (CategoryPlot) ((JFreeChart) chart).getPlot();
            LegendItemCollection liColl = plot.getLegendItems();
            for (int i = 0; i < liColl.getItemCount(); i++) {
                LegendItem li = liColl.get(i);
                String colorStr = (String) params.get(String.valueOf(i));
    <jsp:useBean id="legendItems" class="de.laures.cewolf.example.LegendItemPostProcessor" />
        <cewolf:chartpostprocessor id="legendItems">
            <cewolf:param name="0" value="#FF0000"/>
            <cewolf:param name="1" value="#00FF00"/>
            <cewolf:param name="2" value="#0000FF"/>
            <cewolf:param name="3" value="#FFFFFF"/>
  • Ulf Dittmer

    Ulf Dittmer - 2010-06-27

    Actually, scratch that - it doesn't seem to work; not sure why.


Log in to post a comment.

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

Sign up for the SourceForge newsletter:

No, thanks