Coordinates for XYShapeAnnotation?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
dunabur
Posts: 19
Joined: Sat Jun 24, 2017 12:05 pm
antibot: No, of course not.

Coordinates for XYShapeAnnotation?

Post by dunabur » Thu Jan 10, 2019 4:32 pm

HI,

I am trying to use XYShapeAnnotation to draw shapes in a candlestick chart, at coordinates of specific candles. But I got stuck at the coordinates that have to be given to a shape before it can be drawn.

The DomainAxis consists of date objects. How can I translate those into java coordinates?

thanks alot!

John Matthews
Posts: 513
Joined: Wed Sep 12, 2007 3:18 pm

Re: Coordinates for XYShapeAnnotation?

Post by John Matthews » Thu Jan 10, 2019 8:26 pm

As shown here, XYShapeAnnotation coordinates should be specified relative to the data. As shown here, date values represent the number of milliseconds from the Java epoch. As shown here, use TimeSeries::getDataItem to get a particular TimeSeriesDataItem, and use TimeSeriesDataItem::getPeriod to get the item's timestamp.

dunabur
Posts: 19
Joined: Sat Jun 24, 2017 12:05 pm
antibot: No, of course not.

Re: Coordinates for XYShapeAnnotation?

Post by dunabur » Thu Jan 10, 2019 10:42 pm

Thanks for your answer and the links. I really appreciate it.

There is one thing I don't understand though.

Shapes need int for x and y. But Epoch with milliseconds is long and too big for conversion to int (and y in my case is double, which would be the next problem). How can I use Shapes then? If it is not possible, is there another way to draw geometric shapes (all I need is triangles, rectangles and circles)?

John Matthews
Posts: 513
Joined: Wed Sep 12, 2007 3:18 pm

Re: Coordinates for XYShapeAnnotation?

Post by John Matthews » Fri Jan 11, 2019 2:38 am

The shape's coordinates are data coordinates, not screen coordinates. A typical concrete implementation of java.awt.Shape contains nested classes with constructors that accept float or double arguments, e.g. Ellipse2D.Double in the first example cited.

Locked