How to you remove all chart margins?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
ksevern
Posts: 3
Joined: Wed Aug 27, 2003 6:28 pm

How to you remove all chart margins?

Post by ksevern » Wed Aug 27, 2003 8:06 pm

I'd like to know how to remove all the chart margins. I've had some success getting rid of most of them (see the code below) but need help removing the spaces indicated in this image Image

Please help.

Thanks,
Ken

Code Segment:
______________________________

JFreeChart jfChart = ChartFactory.createLineChart(
null,
null,
null,
jfDataSet,
PlotOrientation.VERTICAL,
false,
false,
false
);

// Customize the chart
jfChart.setBackgroundPaint(Color.WHITE);
jfChart.setAntiAlias(true);
jfChart.setBorderPaint(Color.WHITE);
jfChart.setBorderVisible(false);

// Customize the plot
CategoryPlot plot = jfChart.getCategoryPlot();
plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 0, 0, 0, 0));
plot.setDataAreaRatio(1.0);

// Had to set the paint to white to get rid of this line.
plot.setOutlinePaint(Color.WHITE);



// customize the domain axis...
CategoryAxis domainAxis = plot.getDomainAxis();
domainAxis.setVisible(false);
domainAxis.setUpperMargin(0);
domainAxis.setLowerMargin(0);

// customize the range axis
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setVisible(false);
rangeAxis.setAutoRange(true);
rangeAxis.setAutoRangeIncludesZero(false);
rangeAxis.setUpperMargin(0);
rangeAxis.setLowerMargin(0);

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Thu Aug 28, 2003 8:53 am

The category axis has allocated space for each category, with no gaps in between categories...but since the data points are drawn in the middle of each category, you'll see a "half a category" gap at the start and another "half a category" gap at the end. Switch to a BarRenderer and you'll see what I mean.

One way to eliminate this gap would be to subclass the CategoryAxis class and override the getCategoryStart(...), getCategoryMiddle(...) and getCategoryEnd(...) methods. If you get this to work and don't mind sharing your code, I'd be interested to add an attribute to the CategoryAxis class that allows the "half category" adjustment to be switched on or off.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

ksevern
Posts: 3
Joined: Wed Aug 27, 2003 6:28 pm

Seems like there is more there.

Post by ksevern » Fri Aug 29, 2003 7:43 pm

Thanks for the reply!. That makes sence. I can deal with the half category gap because it should move toward 0 as the number of categories increases. However, I've added 20 data points to the image below and it seems that there is still extra space on the edges.

Is there a way to remove that extra gap?

Thanks,
Ken
Image

Locked