ValueMarker drawn as an arrow

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
SomeOtherUser
Posts: 13
Joined: Thu Apr 06, 2006 7:55 pm

ValueMarker drawn as an arrow

Post by SomeOtherUser » Wed Jan 17, 2007 8:47 pm

I'd like to draw value markers as an arrow instead of a line. The arrow would be at the edge of the chart. I looked through the code to see where markers are drawn (AbstractXYItemRenderer lines 896-911 in my case) and changed some code appropriately. I'm wondering if there isn't a better solution to this.

My code (replacing 896-911 of AbstractXYItemRenderer):

Code: Select all

Polygon arrow = null;
if (orientation == PlotOrientation.HORIZONTAL) {
	arrow = new Polygon(
		new int[] {(int)dataArea.getMaxX(), (int)dataArea.getMaxX() + 5, (int)dataArea.getMaxX() + 5},
		new int[] {(int)v, (int)v - 4, (int)v + 4},
		3);
}
else if (orientation == PlotOrientation.VERTICAL) {
	arrow = new Polygon(
		new int[] {(int)v, (int)v - 4, (int)v + 4},
		new int[] {(int)dataArea.getMinY(), (int)dataArea.getMinY() - 5, (int)dataArea.getMinY() - 5},
		3);
}

g2.setPaint(marker.getPaint());
g2.setStroke(marker.getStroke());
Shape clip = g2.getClip();
g2.setClip(null);
g2.fill(arrow);
g2.setClip(clip);
The swapping out of the clip is necessary because of the solution to interval markers -- possible bug?.

In what ways can JFreeChart support this? A boolean for drawMarkersAsLines/AsArrows? A MarkerRenderer? What is a better solution to drawing the arrows outside the plot's drawable area without swapping out the clip like that?

Thanks.

Locked