How can i get a perfect circle with Ellipse2D?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
sirius
Posts: 1
Joined: Wed Aug 07, 2019 12:55 pm
antibot: No, of course not.

How can i get a perfect circle with Ellipse2D?

Post by sirius » Wed Aug 07, 2019 2:18 pm

Hello folks,

Please help me to solve 2 problems with drawing a circle:

1) I want to make a perfect circle.
Width == Height but it still draws an ellipse:
Image

If you try to rotate this image you'll see what i mean:
Image

How can i get a perfect circle?

2) Image size: 300x300 px. Distances between edges of image and circle are different:

Top: 9 px.
Bottom: 8 px.
Left: 11 px.
Right: 12 px.

I want to get same distances betwen every edge and circle for example:
Top == Bottom == Left == Right == 10 px.

How can i do this?

Here is my code:

public Circle(String title)
{
chart = ChartFactory.createScatterPlot(""/*title*/, "", "", new XYSeriesCollection());

chart.setBorderVisible(false);
chart.removeLegend();

XYPlot plot = ((XYPlot)chart.getPlot());

plot.setBackgroundPaint(Color.WHITE);
plot.setOutlineVisible(false);

double range = 1.45f;

plot.getRangeAxis().setRange(-range, range);
plot.getRangeAxis().setTickLabelsVisible(false);
plot.getRangeAxis().setTickMarksVisible(false);
plot.getRangeAxis().setAxisLineVisible(false);
plot.getRangeAxis().setLowerMargin(0.0f);
plot.getRangeAxis().setUpperMargin(0.0f);

plot.getDomainAxis().setRange(-range, range);
plot.getDomainAxis().setTickLabelsVisible(false);
plot.getDomainAxis().setTickMarksVisible(false);
plot.getDomainAxis().setAxisLineVisible(false);
plot.getDomainAxis().setLowerMargin(0.0f);
plot.getDomainAxis().setUpperMargin(0.0f);

double outRad = range - 0.01f;

Ellipse2D outercircle = new Ellipse2D.Double(0.0f - outRad, 0.0f - outRad, outRad * 2.0f, outRad * 2.0f);

plot.addAnnotation(new XYShapeAnnotation(outercircle, new BasicStroke(2.0f), Color.BLACK));
}

Thanks.

Locked