Hi,
I have a time series graph , I want to highlight a particular point in the graph which will indicate the peak value in the graph , Is it possible to highlight a particular point say with green circle?
Please help.
Thanks
Deepak
Is it possible to mark a visible point on a graph?
Add one of these to your plot
Code: Select all
org.jfree.chart.annotations.XYShapeAnnotation
Thanks it was a nice pointer , Though i had to do a lot of google after the start you gave.
Here is what worked for me
1) Write a custom class
class CircleDrawer implements Drawable {
/** The outline paint. */
private Paint outlinePaint;
/** The outline stroke. */
private Stroke outlineStroke;
/** The fill paint. */
private Paint fillPaint;
/**
* @param outlinePaint the outline paint.
* @param outlineStroke the outline stroke.
* @param fillPaint the fill paint.
*/
public CircleDrawer(final Paint outlinePaint,
final Stroke outlineStroke,
final Paint fillPaint) {
this.outlinePaint = outlinePaint;
this.outlineStroke = outlineStroke;
this.fillPaint = fillPaint;
}
/**
* Draws the circle.
*
* @param g2 the graphics device.
* @param area the area in which to draw.
*/
public void draw(final Graphics2D g2, final Rectangle2D area) {
final Ellipse2D circle = new Ellipse2D.Double(area.getX(), area.getY(),
area.getWidth(), area.getHeight());
if (fillPaint != null) {
g2.setPaint(fillPaint);
g2.fill(circle);
}
if (this.outlinePaint != null && this.outlineStroke != null) {
g2.setStroke(outlineStroke);
g2.setPaint(outlinePaint);
g2.draw(circle);
}
}
}
2) Add the custom drawer as a annotation to XYPlot
final CircleDrawer cd = new CircleDrawer(Color.red, new BasicStroke(1.0f), Color.red);
final XYAnnotation point = new XYDrawableAnnotation(<VALUE_IN_XAXIS>,<VALUE_IN_YAXIS>, 5, 5, cd);
(XYPlot) chart.getPlot().addAnnotation(point);
Hope this will help others as well.
Thanks
Deepak
Here is what worked for me
1) Write a custom class
class CircleDrawer implements Drawable {
/** The outline paint. */
private Paint outlinePaint;
/** The outline stroke. */
private Stroke outlineStroke;
/** The fill paint. */
private Paint fillPaint;
/**
* @param outlinePaint the outline paint.
* @param outlineStroke the outline stroke.
* @param fillPaint the fill paint.
*/
public CircleDrawer(final Paint outlinePaint,
final Stroke outlineStroke,
final Paint fillPaint) {
this.outlinePaint = outlinePaint;
this.outlineStroke = outlineStroke;
this.fillPaint = fillPaint;
}
/**
* Draws the circle.
*
* @param g2 the graphics device.
* @param area the area in which to draw.
*/
public void draw(final Graphics2D g2, final Rectangle2D area) {
final Ellipse2D circle = new Ellipse2D.Double(area.getX(), area.getY(),
area.getWidth(), area.getHeight());
if (fillPaint != null) {
g2.setPaint(fillPaint);
g2.fill(circle);
}
if (this.outlinePaint != null && this.outlineStroke != null) {
g2.setStroke(outlineStroke);
g2.setPaint(outlinePaint);
g2.draw(circle);
}
}
}
2) Add the custom drawer as a annotation to XYPlot
final CircleDrawer cd = new CircleDrawer(Color.red, new BasicStroke(1.0f), Color.red);
final XYAnnotation point = new XYDrawableAnnotation(<VALUE_IN_XAXIS>,<VALUE_IN_YAXIS>, 5, 5, cd);
(XYPlot) chart.getPlot().addAnnotation(point);
Hope this will help others as well.
Thanks
Deepak
Zzzzz....
Did you try this?
Code: Select all
chart.getXYPlot().addAnnotation(new XYShapeAnnotation(new Ellipse2D.Double(...)...));