XYTextAnnotation with highlighted Box

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
develop
Posts: 296
Joined: Wed Mar 23, 2005 10:01 pm

XYTextAnnotation with highlighted Box

Post by develop » Thu Mar 26, 2009 3:51 pm

I need to show some values on chart. i am using XYTextAnnotation. but i need to draw colored box around it.

see below picture, this is what i am trying to achieve.
any idea how to do this ??

Image

Thanks

mkivinie
Posts: 51
Joined: Wed Jul 06, 2005 8:35 am

Re: XYTextAnnotation with highlighted Box

Post by mkivinie » Fri Mar 27, 2009 11:39 am

You could either
- create an XYBoxAnnotation with your desired color and add it so that it matches the coordinates of your XYTextAnnotation.
When you add annotations to the renderer you can define the Layer (BACKGROUND/FOREGROUND) so color box to the background and text to the foreground

- or create your own Annotation implementation that does both the text and color

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: XYTextAnnotation with highlighted Box

Post by david.gilbert » Fri Mar 27, 2009 12:37 pm

XYTextAnnotation has been updated in Subversion a little while ago to support this (to be included in the 1.0.13 release):

http://jfreechart.svn.sourceforge.net/v ... otate=1887
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

develop
Posts: 296
Joined: Wed Mar 23, 2005 10:01 pm

Re: XYTextAnnotation with highlighted Box

Post by develop » Tue Mar 31, 2009 1:42 pm

Thanks a lot. this is exactly i wanted.
One more question. my chart is real time. meaning only last candle updates in real time, and i need to highlight values. for that i was using XYTextAnnotation.
how can i make annotation values dynamic ?
so that it reflect the real time changes and highlight those changes ?

Garfke
Posts: 5
Joined: Tue Sep 29, 2009 10:23 am
antibot: No, of course not.

Re: XYTextAnnotation with highlighted Box

Post by Garfke » Tue Sep 29, 2009 10:29 am

david.gilbert wrote:XYTextAnnotation has been updated in Subversion a little while ago to support this (to be included in the 1.0.13 release):

http://jfreechart.svn.sourceforge.net/v ... otate=1887
I get a very strange exception when a I try to draw an outline :

My code :

Code: Select all

        XYTextAnnotation annotation = new XYTextAnnotation("V",100,10);
        annotation.setOutlineVisible(true);
        annotation.setFont(new Font("SansSerif", Font.BOLD, 12));
        annotation.setPaint(Color.blue);
        plot.addAnnotation(annotation);
The exception :

Code: Select all

Exception in thread "main" java.lang.NoSuchMethodError: org.jfree.chart.annotations.XYTextAnnotation.setOutlineVisible(Z)V
I have no idea what the problem is, anyone?

TomHart
Posts: 7
Joined: Tue Sep 29, 2009 2:57 pm
antibot: No, of course not.

Re: XYTextAnnotation with highlighted Box

Post by TomHart » Tue Sep 29, 2009 4:54 pm

One thing you can do is to 1) create an annotation that draws the values need to be displayed 2) Hold a reference to this annotation 3) Make sure you remove this annotaion when a price change is notified 4) Add a new annotation with the latest values. This works for me as I need to do exactly the samething as you do. However, my requirement is to display the price as the user mouse hovers on the chart. This takes care of it.

Locked