How to change the background color of a JasperReports chart

The default background color for a JasperReports chart is blue.

I want to change this background color.

How can I change it?

+2


a source to share


2 answers


If you are using iReport, select chart properties and change the background property to your desired color.

If there is no XML for the chart, there must be an xml tag with a name <itemLabel>

.



Within this, you can set the foreground and background of the chart as shown below.

<itemLabel color="#000000" backgroundColor="#FFFFFF"/>

      

0


a source


I had this problem. Contrary to even some official docs, the tag itemLabel

does not affect the appearance of the chart.

Instead, to set the background color of the entire chart area, create or change an attribute backcolor

in the tag reportElement

for your chart. For instance:

<barChart>
    <chart>
        <reportElement mode="Opaque" backcolor="#CCCCCC" x="0" y="0" width="400" height="400"/>
...

      

Note that the attribute mode

must be set to "Opaque"

for the displayed color. If you are using iReport you can of course change the color using the properties tab.



If you only want to set the background color for the actual chart (the area inside the axes where the data is displayed), set the attribute backcolor

on the plot

chart element . For instance:

<barChart>
...
    <barPlot>
        <plot backcolor="#CCCCCC"/>
...

      

This doesn't show up in the properties tab, so you'll need to edit the xml directly.

0


a source







All Articles