Javier
Javier

Reputation: 12398

Remove separation between bar and axis line in JFreeChart

Is it possible to remove the distance between the bar and the axis line in a JFreeChart bar chart?

I have produced a bar chart that looks like (A), but I would like it to look like (B), i.e. without any separation between the bar and the (darker) axis line. The axis line is configured as:

    plot.getDomainAxis().setAxisLinePaint(new Color(0x333333));
    plot.getDomainAxis().setAxisLineStroke(new BasicStroke(1.0f));

I couldn't find the relevant setting for this purpose.

(A) actual and (B) intended chart

Edit: the demo chart at BarRenderer javadoc, also shows the same issue.

enter image description here

Upvotes: 3

Views: 963

Answers (2)

Javier
Javier

Reputation: 12398

That space is called axis offset. The StandardChartTheme applies an axisOffset of 4px.

In order to remove the axis offset configure:

CategoryPlot plot = chart.getCategoryPlot();
plot.setAxisOffset(new RectangleInsets(0, 0, 0, 0));

The axis offset can also be configured at the theme level: StandardChartTheme.setAxisOffset

Upvotes: 4

M Zippka
M Zippka

Reputation: 103

remove the margin with:

BarRenderer(renderer)).setItemMargin(0.0);

Upvotes: 0

Related Questions