# Highlight interval on easy chart

**URL:** <https://forum.inductiveautomation.com/t/highlight-interval-on-easy-chart/19764>\
**Category:** Ignition\
**Created:** [September 21, 2018, 2:59pm UTC](https://forum.inductiveautomation.com/t/highlight-interval-on-easy-chart/19764 "2018-09-21T14:59:52Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![nicholas](https://avatars.discourse-cdn.com/v4/letter/n/4da419/32.png) [@nicholas](https://forum.inductiveautomation.com/u/nicholas)\
**Post date:** [September 21, 2018, 2:59pm UTC](https://forum.inductiveautomation.com/t/highlight-interval-on-easy-chart/19764/1 "2018-09-21T14:59:52Z")

</div>

Hello everyone,

Does anyone know the best way to go about adding a highlight overlay for a specific time interval to an easy chart? It should look something along the lines of this image below. A bar or something at the top would do aswell, I just need something to bring attention to a specified time interval.  
 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/0/0b8d1c0fc86cea984f93fe2276877d7c9883e4cb.png)

Thanks.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [September 21, 2018, 3:31pm UTC](https://forum.inductiveautomation.com/t/highlight-interval-on-easy-chart/19764/2 "2018-09-21T15:31:10Z")

</div>

I don’t have a reference handy on this (I’ll probably circle back to this later and fill in the details) but to get you started, you’ll need to use the `configureChart` extension function to drill into the chart’s [`XYPlot`](http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/plot/XYPlot.html), which has an `addAnnotation()` method. You can pass an [`XYShapeAnnotation`](http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/annotations/XYShapeAnnotation.html) into that method, which you will need to create yourself using a basic Java Shape (eg, [`Rectangle2D`](https://docs.oracle.com/javase/8/docs/api/java/awt/geom/Rectangle2D.html)).

---

<div class="post-metadata">

**Author:** ![nicholas](https://avatars.discourse-cdn.com/v4/letter/n/4da419/32.png) [@nicholas](https://forum.inductiveautomation.com/u/nicholas)\
**Post date:** [September 21, 2018, 4:59pm UTC](https://forum.inductiveautomation.com/t/highlight-interval-on-easy-chart/19764/3 "2018-09-21T16:59:51Z")

</div>

`addAnnotation()` should work. It looks like it takes an object that implements [XYAnnotation](http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/annotations/XYAnnotation.html). I tried importing `org.jfree.chart.annotations.XYShapeAnnotation` but the import path was invalid. Do you know how to find the import path for these XYPlot objects?

---

<div class="post-metadata">

**Author:** ![Stevenson.Yuan](https://avatars.discourse-cdn.com/v4/letter/s/ac91a4/32.png) [@Stevenson.Yuan](https://forum.inductiveautomation.com/u/Stevenson.Yuan)\
**Post date:** [September 21, 2018, 5:26pm UTC](https://forum.inductiveautomation.com/t/highlight-interval-on-easy-chart/19764/4 "2018-09-21T17:26:08Z")

</div>

What does your import statement look like?

This appears to work for me:

> from org.jfree.chart.annotations import XYShapeAnnotation

---

<div class="post-metadata">

**Author:** ![nicholas](https://avatars.discourse-cdn.com/v4/letter/n/4da419/32.png) [@nicholas](https://forum.inductiveautomation.com/u/nicholas)\
**Post date:** [September 21, 2018, 5:34pm UTC](https://forum.inductiveautomation.com/t/highlight-interval-on-easy-chart/19764/5 "2018-09-21T17:34:47Z")

</div>

I may have misspelled something. That works fine for me now.  
It seems to be adding the overlay without an error now. The problem is that it does not appear on screen. Is there anything else that needs to be done to make the box show up?

```auto
	from org.jfree.chart.annotations import XYBoxAnnotation
	from java.awt import BasicStroke, Color
	
	stroke = BasicStroke(1)
	outline = Color(255, 0, 0)
	fill = Color(0, 255, 0)
	
	overlay = XYBoxAnnotation(10, 10, 100, 100, stroke, outline, fill)
	chart.getXYPlot().addAnnotation(overlay)
	
	print 'added overlay'

```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [September 21, 2018, 5:42pm UTC](https://forum.inductiveautomation.com/t/highlight-interval-on-easy-chart/19764/6 "2018-09-21T17:42:53Z")

</div>

Try specifying the X coordinates as epoch milliseconds, rather than 10/10.

---

<div class="post-metadata">

**Author:** ![nicholas](https://avatars.discourse-cdn.com/v4/letter/n/4da419/32.png) [@nicholas](https://forum.inductiveautomation.com/u/nicholas)\
**Post date:** [September 21, 2018, 5:56pm UTC](https://forum.inductiveautomation.com/t/highlight-interval-on-easy-chart/19764/7 "2018-09-21T17:56:32Z")

</div>

Ah, I was thinking it would be pixels. That is a much better interface anyways. I got it working with this code for future reference.

```auto
	from org.jfree.chart.annotations import XYBoxAnnotation
	from java.awt import BasicStroke, Color
	
	stroke = BasicStroke(0)
	outline = Color(0, 0, 0)
	fill = Color(0, 255, 0, 127)
	
	minuteOffset = 60000
	startX = self.startDate.getTime() + minuteOffset
	endX = self.endDate.getTime() - minuteOffset
	bottomY = 20
	topY = 80
	
	overlay = XYBoxAnnotation(startX, bottomY, endX, topY, stroke, outline, fill)
	chart.getXYPlot().addAnnotation(overlay)
	
	print 'updated overlay'

```

![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/f/f43f30c11e04bef030d08c865a264bd29de60c14.png)

Do you know when the `configureChart()` function is invoked?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [September 21, 2018, 7:31pm UTC](https://forum.inductiveautomation.com/t/highlight-interval-on-easy-chart/19764/8 "2018-09-21T19:31:00Z")

</div>

`configureChart` gets fired a couple different places, but basically you can rely on it getting fired any time your chart’s data changes.
