Search code examples
javaswingjfreechart

JFreeChart Polar chart custom X labels


I would like to customize my PolarChart to replace the angle values displayed in a PolarChart by default enter image description here , with custom strings like this : enter image description here


Solution

  • You can override the refreshAngleTicks() method of PolarPlot, as shown here:

    import static org.jfree.ui.TextAnchor.*
    …
    PolarPlot plot = new PolarPlot() {
    
        @Override
        protected List refreshAngleTicks() {
            List ticks = new ArrayList();
            ticks.add(new NumberTick(0, "maxCharTick: 20", TOP_LEFT, TOP_LEFT, 0));
            ticks.add(new NumberTick(45, "energyComsuption: 1", TOP_LEFT, TOP_LEFT, 0));
            ticks.add(new NumberTick(90, "maxDamage: 40", TOP_LEFT, TOP_LEFT, 0));
            …
            return ticks;
        }
    };
    

    Alternatively, consider a SpiderWebPlot, shown here.