Annotations in XYPlot

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Marko

Annotations in XYPlot

Post by Marko » Wed Aug 07, 2002 10:36 pm

Hi all,

actually I have two questions regarding an XYPlot.

1) Is it possible to draw vertical lines (maybe even dashed?) into an XYPlot? If so, how?

2) Looks like annotations are currently not supported by jfreechart. I'm trying to draw something like little markes over certain points of an XYSeries in an XYPlot. What concept should I use to add this functionallity? Can you give me a hint? I have trouble finding the right place to start drilling ;-)...

Thanks a lot!

Cheers,

Marko

David Gilbert

Re: Annotations in XYPlot

Post by David Gilbert » Thu Aug 08, 2002 7:05 am

Marko wrote:
> 1) Is it possible to draw vertical lines (maybe even dashed?)
> into an XYPlot? If so, how?

There are methods in XYPlot for this:

addHorizontalLine(...)
addVerticalLine(...)

In CategoryPlot a similar method is addRangeMarker(...). I plan to change XYPlot to use addDomainMarker(...) and addRangeMarker(...) for consistency (and also because then all formatting can be encapsulated in the Marker class...for example, a Stroke setting could easily be added).

> 2) Looks like annotations are currently not supported by
> jfreechart. I'm trying to draw something like little markes
> over certain points of an XYSeries in an XYPlot. What concept
> should I use to add this functionallity? Can you give me a
> hint? I have trouble finding the right place to start
> drilling ;-)...

I'd like to have a general mechanism for adding text items, arrows, other symbols etc, but haven't implemented it yet. It would probably fit into the XYPlot class (with something similar in CategoryPlot) in much the same way as the horizontal and vertical line support that is already there).

One other approach is to use an OverlaidXYPlot and drive your symbols from a dataset. I think this is the purpose of the SignalRenderer class and related classes (in a stock charting context) though I've never used it.

Regards,

DG.

Marko

Re: Annotations in XYPlot

Post by Marko » Thu Aug 08, 2002 12:58 pm

Thanks for the comprehensive answer.

I tried adding a horizontal line, but nothing happened:


JFreeChart chart =
ChartFactory.createXYChart(chartData.getChartHeading(), chartData.getXAxisLabel(), chartData.getYAxisLabel(),
dataset, true);


XYPlot xyPlot = (XYPlot)chart.getPlot();
xyPlot.addHorizontalLine(new Double(50.0), Color.blue);

Marko

Re: Annotations in XYPlot

Post by Marko » Thu Aug 08, 2002 1:02 pm

Sorry, I found the problem myself (one of these that make you ask yourself if you are ...)

Cheers,

Marko

Wolfgang Lenhard

Re: Annotations in XYPlot

Post by Wolfgang Lenhard » Thu Aug 22, 2002 11:09 am

Please, give me a hint!
I have got a VerticalBarChart3D, and

chart.getXYPlot().addHorizontalLine(new Double(50.0), Color.blue);

always produces

Exception occurred during event dispatching:
java.lang.ClassCastException: com.jrefinery.chart.VerticalCategoryPlot
at com.jrefinery.chart.JFreeChart.getXYPlot(Unknown Source)

I just can't figure out, what is going wrong.

David Gilbert

Re: Annotations in XYPlot

Post by David Gilbert » Thu Aug 22, 2002 11:50 am

Hi Wolfgang,

The chart you are using is based on CategoryPlot not XYPlot, so you need to do this:

CategoryPlot plot = myChart.getCategoryPlot();
plot.setRangeMarker(new Marker(...));

The setRangeMarker(...) method adds a line perpendicular to the range axis on most category plots.

By the way, in the next release, the XYPlot class will use setDomainMarker(...) and setRangeMarker(...) rather than addHorizontalLine and addVerticalLine, to be consistent with CategoryPlot.

Regards,

DG.

Wolfgang Lenhard

Re: Annotations in XYPlot

Post by Wolfgang Lenhard » Thu Aug 22, 2002 5:39 pm

Thank you very much for your support.

As a java novice, it took several days to figure out, how jFreeChart works.
At the meantime, I would describe myself as an JFreeChart-enthusiast!

Greetings to all coders of JFreeChart!

P.S.: One single question ist left. The marker is in 3D, but shows up behind the 3D-bar. The bar should go just through it instead. Is there already a function to fix this?

Locked