Adding an Annotation to a Category Chart

I found a way to do it here :

viewtopic.php?f=70&t=6402&p=18059&hilit=xytextAnnotation#p18059

Unfortunately I am not very familiar with java and am having a tough time navigating the jfreechart API to do the same thing with a category chart.

Could someone point me in the right direction?

Thanks,

Mike

You would do something similar but use the category text annotation:from org.jfree.chart.annotations import CategoryTextAnnotation chart = event.source.parent.getComponent("Chart") plot = chart.getChart().getCategoryPlot() plot.addAnnotation(CategoryTextAnnotation("Hello World", "Category", 25.0))

Thanks. This worked.

I am confused though because the categoryItemRenderer had nothing about addAnnotation(). addAnnotation only appears under Interface XYItemRenderer.

The categoryItemRenderer isn’t the object being used to add the annotation. The CategoryPlot object returned by the chart.getChart().getCategoryPlot() is what has the addAnnotation() method.

I tried to extend this to change the font/color of the Annotation and i’m running into some syntax errors.

[code]from org.jfree.chart.annotations import CategoryTextAnnotation
chart = event.source.parent.getComponent(“Chart”)
plot = chart.getChart().getCategoryPlot()
from java.util import Date

data = system.dataset.toPyDataSet(event.source.parent.getComponent(‘Chart’).Data)
for row in data:
a1 = CategoryTextAnnotation((“Hours: %s” % row[1]), row[0], 1.02)
a1.setFont(Font(‘Courier New’, Font.ITALIC, 12))
plot.addAnnotation(a1)
[/code]

NameError: name ‘Font’ is not defined

I seem to be missing something here, help? :slight_smile:

Looks like you forgot to import Font:

from java.awt import Font

Ohh it is always the little things…

Thanks James