Marker class, addDomainMarker, addRangeMarker

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

Marker class, addDomainMarker, addRangeMarker

Post by Hostos Monegro » Fri Oct 25, 2002 12:12 am

I've included my code for reference........

What I'm trying to do is draw a vertical line perpendiculer to the x-axis of CombinedXYPlot (to use as a threshold, or marker) whos x-axis consists of dates (HorizontalDateAxis). My code below is currently drawing a horizontal line on my first subplot, whose y-axis consists of numbers.

My Questions:

1. So, you can see that I know how to draw a line (the threshold) on an axis which is made up of numbers. So, how do I draw a vertical line on the x-axis made up of dates?


My code:
-----------------------------------------------------------------------------------------------
// create subplot 1...
XYDataset data1 = this.createDataset1();
XYItemRenderer renderer1 = new StandardXYItemRenderer();
renderer1.setToolTipGenerator(new TimeSeriesToolTipGenerator("d/MMM/yyyy", "0,000.0"));
XYPlot subplot1 = new XYPlot(data1, null, new VerticalNumberAxis("Units"), renderer1);
Marker marker = new Marker(200.00,Color.red, new java.awt.BasicStroke(0.5f), Color.red, 0.80f);
subplot1.addRangeMarker(marker);

// create a parent plot...
CombinedXYPlot plot = new CombinedXYPlot(new HorizontalDateAxis("March"), CombinedXYPlot.VERTICAL);

// add the subplots...
plot.add(subplot1, 2);
--------------------------------------------------------------------------------------


Thanks again,
Hostos

Dave Gilbert

Re: Marker class, addDomainMarker, addRangeMarker

Post by Dave Gilbert » Fri Oct 25, 2002 9:13 am

The trick is to remember that date axes are measured in "milliseconds since midnight 1 Jan 1970 GMT" (the same encoding as java.util.Date). So if you create a Date object for the point you wish to mark, then get the milliseconds as a number, you can then create a Marker using this number. Then just use addDomainMarker(...).

Regards,

DG.

P.S. I think it will be a good idea if I add more constructors to the Marker class to accept Date arguments and do the conversion internally.

Hostos Monegro

Re: Marker class, addDomainMarker, addRangeMarker

Post by Hostos Monegro » Fri Oct 25, 2002 3:24 pm

Thanks Dave, that was some very useful insight on what is actually going on. I used the code below and its working great.


my code:
-----------------------------------------------------------------------------------------------
Date date = new Date(102,2,6);
XYPlot subplot1 = new XYPlot(data1, null, new VerticalNumberAxis("Units(000s)"), renderer1);
subplot1.addDomainMarker(new Marker(date.getTime(),Color.red, new java.awt.BasicStroke(2.5f), Color.red, 0.80f));
-----------------------------------------------------------------------------------------------


thanks again,
Hostos

Locked