Manuel Leduc
Manuel Leduc

Reputation: 1919

JasperReports chart configuration

I need to generate a chart like this sample : chart sample

In this sample values are corrects but I must change to details :

1) On the value axis, I want to hide any not integer values (1.75, 1.25 ...)
2) I want each category of category axis to be in a different color.

Is there a way to configure my JasperReports so it will behave as I expect it will ?

Upvotes: 1

Views: 8995

Answers (2)

mdahlman
mdahlman

Reputation: 9400

1) In iReport you can set the Minimum Tick Interval. Set that to "1", and you might get exactly what you need without any coding. It would work in the example you have posted. But it won't work in all cases. For example, you could still get a chart with tick marks at 0, 2.5, 5, 7.5, 10. Start with this idea before looking into chart customizers.

1b) You need a chart customizer or a chart theme to be certain the axis is exactly what you want in all cases. I really hate those non-integer tick marks too! You could use the chart customizer here to solve it. That would give you the desired result with no further Java coding needed.

2) Conceptually you have 1 series plotted on 3 categories in your example. You could swap this and plot 3 series in a single category. You might call the category "" or "dummy" but not display it. Results:

  • 3 differently colored bars. (hooray!)
  • Category descriptions are gone. (boo!)
  • Legend could replace the category descriptions. (good enough?)

2b) Of course you could use a chart customizer to get precisely what you want... but the extra effort might be too much (or indeed, impossible if you don't have a Java background).

Upvotes: 4

trashgod
trashgod

Reputation: 205875

  1. Invoke setTickUnit() on the range axis, as shown here.

  2. Override getItemPaint(), as shown here.

Upvotes: 4

Related Questions