value axis tick cutomizer

0

I am having an issue which is can we add the “%” in the value axis. e.g. instead of (0,5,10…..) in the y axis can we have (0.0 % , 5.0% , 10.0%).the “value axis tick level mask” mask is not working in jasper server.

the thread  "http://community.jaspersoft.com/questions/539134/value-axis-tick-label-e..."  relates closely to my problem. I have attached the images.The required.jpeg  file is what actually needs to be done and current chart,jpeg shows what i am actually getting.

Thanks

cjasper's picture
63
Joined: Jul 24 2012 - 7:20am
Last seen: 1 year 6 months ago

2 Answers:

1

 

1.   You  will need to add below in the iReport XML part directly. Somehow jasper does not take “Value Axis Tick Label Mask” property from Chart Properties window.                                      

                                                                              

2. Save report from xml window, then open design window and save report to repository.

 

 

ajinkya_c's picture
935
Joined: Aug 29 2012 - 6:13am
Last seen: 2 years 8 months ago

hi @ajinkya_c .Thanks for the reply.I did this using customizer class.I will try this option too.

cjasper - 6 years 11 months ago

Can you please share how you do with customizer class ?.

ajinkya_c - 6 years 11 months ago
2

 

Hi . this is the method i used to customize it 
 
public void customize(JFreeChart chart, JRChart jasperChart) {
        Plot plot = chart.getPlot();
 
        if (plot instanceof CategoryPlot) {
            CategoryPlot catPlot = (CategoryPlot) plot;
 
 
            BarRenderer renderer = (BarRenderer) catPlot.getRenderer();
            //ser bar widht
            renderer.setMaximumBarWidth(0.07);
            //set margin between two bar('of one year')
            renderer.setItemMargin(0.0f);
 
            NumberAxis leftNumberAxis = (NumberAxis) catPlot.getRangeAxis();
            leftNumberAxis.setUpperMargin(0.30);
            leftNumberAxis.setNumberFormatOverride(new NumberFormat() {
 
                @Override
                public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) {
 
                    return new StringBuffer(String.valueOf(number).concat("%"));
                }
 
                @Override
                public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos) {
 
 
 
                    return new StringBuffer(String.valueOf(number).concat("%"));
                }
 
                @Override
                public Number parse(String source, ParsePosition parsePosition) {
                    throw new UnsupportedOperationException("Not supported yet.");
                }
            });
        }
    }
cjasper's picture
63
Joined: Jul 24 2012 - 7:20am
Last seen: 1 year 6 months ago

Thanks for reply

ajinkya_c - 6 years 11 months ago

A shorter way to do cjasper's solution is something like this:

public class MyCustomizer implements JRChartCustomizer {

@Override
public void customize(JFreeChart chart, JRChart jasperChart) {
NumberAxis numAxis = (NumberAxis) chart.getCategoryPlot().getRangeAxis();
numAxis.setNumberFormatOverride(new DecimalFormat("#,##0"));
}
}

swarm357 - 6 years 11 months ago
Feedback