Akriti Saini
Akriti Saini

Reputation: 1

Category Axis Label Expression Alignment In jasper Report through Java code

Is there any way, to change Category Axis Label Expression's Alignment of a Chart in Jasper Report through Java Code. I want Left alignment of Category Axis Label Expression. As shown the picture below, I want "hello" to be left aligned.

given picture

Upvotes: 0

Views: 1262

Answers (1)

trashgod
trashgod

Reputation: 205785

Starting with BarChartDemo1, included in the distribution, the changes below create a bar chart with an axis label having its location set to the LOW_END. For PlotOrientation.VERTICAL, that means aligned on the left.

JFreeChart chart = ChartFactory.createBarChart(
    "Performance: JFreeSVG vs Batik",
    "$P{hello}" /* x-axis label*/,
    "Milliseconds" /* y-axis label */,
    dataset, PlotOrientation.VERTICAL, false, false, false);
…
CategoryPlot plot = (CategoryPlot) chart.getPlot();
CategoryAxis domainAxis = plot.getDomainAxis();
domainAxis.setLabelLocation(AxisLabelLocation.LOW_END);

image

Try doing the same for the range axis to see the effect:

rangeAxis.setLabelLocation(AxisLabelLocation.LOW_END);

Upvotes: 1

Related Questions