Search code examples
jasper-reportsjfreechartpie-chart

How to remove box around label in piechart?


Does anyone know how to remove the box/border around label in jasperreport piechart? What do I need to include in the .jrxml file so that the label displayed with no border.


Solution

  • Add a JRChartCustomizer, setting labelOutlinePaint and labelShadowPaint to null in plot

    Example

    Java customizer

    public class NoLabelCustomizer implements JRChartCustomizer{
        @Override
        public void customize(JFreeChart chart, JRChart jrchart) {
            PiePlot plot = (PiePlot) chart.getPlot();
             plot.setLabelOutlinePaint(null);
             plot.setLabelShadowPaint(null);    
        }
    }
    

    jrxml

    <pie3DChart>
        <chart isShowLegend="false" customizerClass="NoLabelCustomizer">
                <reportElement mode="Opaque" x="225" y="0" width="320" height="140" backcolor="#FFFFFF" uuid="23bd26a6-04a4-406f-8a1a-5e1b260cb75d"/>
                <chartTitle/>
                <chartSubtitle/>
                <chartLegend/>
                <anchorNameExpression><![CDATA["Graph"]]></anchorNameExpression>
                <hyperlinkTooltipExpression><![CDATA["Graph"]]></hyperlinkTooltipExpression>
        </chart>
        <pieDataset>
                <keyExpression><![CDATA[$F{User}]]></keyExpression>
                <valueExpression><![CDATA[$F{Rep}]]></valueExpression>
        </pieDataset>
        <pie3DPlot isShowLabels="true">
                <plot/>
                <itemLabel/>
        </pie3DPlot>
    </pie3DChart>
    

    Note the customizerClass="NoLabelCustomizer" on the chart tag

    Output (using datasource from this question)

    Result