# Adding an Annotation to a Category Chart

**URL:** <https://forum.inductiveautomation.com/t/adding-an-annotation-to-a-category-chart/6175>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [April 8, 2013, 7:25pm UTC](https://forum.inductiveautomation.com/t/adding-an-annotation-to-a-category-chart/6175 "2013-04-08T19:25:44Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![mikehill100](https://avatars.discourse-cdn.com/v4/letter/m/bcef8e/32.png) [@mikehill100](https://forum.inductiveautomation.com/u/mikehill100)\
**Post date:** [April 8, 2013, 7:25pm UTC](https://forum.inductiveautomation.com/t/adding-an-annotation-to-a-category-chart/6175/1 "2013-04-08T19:25:44Z")

</div>

I found a way to do it here :

[viewtopic.php?f=70&t=6402&p=18059&hilit=xytextAnnotation#p18059](http://www.inductiveautomation.com/forum/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

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [April 8, 2013, 9:42pm UTC](https://forum.inductiveautomation.com/t/adding-an-annotation-to-a-category-chart/6175/2 "2013-04-08T21:42:51Z")

</div>

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))`

---

<div class="post-metadata">

**Author:** ![mikehill100](https://avatars.discourse-cdn.com/v4/letter/m/bcef8e/32.png) [@mikehill100](https://forum.inductiveautomation.com/u/mikehill100)\
**Post date:** [April 9, 2013, 4:59pm UTC](https://forum.inductiveautomation.com/t/adding-an-annotation-to-a-category-chart/6175/3 "2013-04-09T16:59:10Z")

</div>

Thanks. This worked.

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

---

<div class="post-metadata">

**Author:** ![dave.fogle](https://avatars.discourse-cdn.com/v4/letter/d/43a26b/32.png) [@dave.fogle](https://forum.inductiveautomation.com/u/dave.fogle)\
**Post date:** [April 9, 2013, 10:47pm UTC](https://forum.inductiveautomation.com/t/adding-an-annotation-to-a-category-chart/6175/4 "2013-04-09T22:47:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Dravik](https://avatars.discourse-cdn.com/v4/letter/d/e274bd/32.png) [@Dravik](https://forum.inductiveautomation.com/u/Dravik)\
**Post date:** [May 7, 2013, 9:25pm UTC](https://forum.inductiveautomation.com/t/adding-an-annotation-to-a-category-chart/6175/5 "2013-05-07T21:25:45Z")

</div>

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? 🙂

---

<div class="post-metadata">

**Author:** ![James.Lorenz](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/james.lorenz/32/3290_2.png) [@James.Lorenz](https://forum.inductiveautomation.com/u/James.Lorenz)\
**Post date:** [May 7, 2013, 10:19pm UTC](https://forum.inductiveautomation.com/t/adding-an-annotation-to-a-category-chart/6175/6 "2013-05-07T22:19:51Z")

</div>

Looks like you forgot to import Font:

```auto
from java.awt import Font
```

---

<div class="post-metadata">

**Author:** ![Dravik](https://avatars.discourse-cdn.com/v4/letter/d/e274bd/32.png) [@Dravik](https://forum.inductiveautomation.com/u/Dravik)\
**Post date:** [May 7, 2013, 10:26pm UTC](https://forum.inductiveautomation.com/t/adding-an-annotation-to-a-category-chart/6175/7 "2013-05-07T22:26:17Z")

</div>

Ohh it is always the little things…

Thanks James

---

<div class="post-metadata">

**Author:** ![Sheik\_Zaheem](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@Sheik\_Zaheem](https://forum.inductiveautomation.com/u/Sheik_Zaheem)\
**Post date:** [August 8, 2023, 7:36am UTC](https://forum.inductiveautomation.com/t/adding-an-annotation-to-a-category-chart/6175/8 "2023-08-08T07:36:30Z")

</div>

AttributeError: 'org.jfree.chart.renderer.category.LineAndShapeRend' object has no attribute 'addAnnotation'

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [August 8, 2023, 12:37pm UTC](https://forum.inductiveautomation.com/t/adding-an-annotation-to-a-category-chart/6175/9 "2023-08-08T12:37:15Z")

</div>

That is explained above.
