# Show tooltipText in foreground of the Status Chart - Vision

**URL:** <https://forum.inductiveautomation.com/t/show-tooltiptext-in-foreground-of-the-status-chart-vision/69084>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [January 27, 2023, 8:08am UTC](https://forum.inductiveautomation.com/t/show-tooltiptext-in-foreground-of-the-status-chart-vision/69084 "2023-01-27T08:08:19Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [February 20, 2023, 10:49am UTC](https://forum.inductiveautomation.com/t/show-tooltiptext-in-foreground-of-the-status-chart-vision/69084/7 "2023-02-20T10:49:28Z")

</div>

I finally developed a reliable way to achieve this result. Initially, I tried various label generators, but all I could get them to do is apply a single label to each series, so it appears that I was mistaken in my initial suggestion.

What ended up working quite well are XYTextAnnotations. Below is a script that iterates through the chart data, and calculates the appropriate place to put the annotations. Since timeDiff is what was requested in the original post, in the below example, I calculate it for each data block and apply it accordingly.

**Here is the script:**

```auto
from org.jfree.chart.annotations import XYTextAnnotation
from java.awt import Color
chartComponent = system.gui.getParentWindow(event).getComponentForPath('Root Container.Status Chart')
data = chartComponent.data
chart = chartComponent.chart
plot = chart.XYPlot
for annotation in plot.getAnnotations():
    if isinstance(annotation, XYTextAnnotation):
    	plot.removeAnnotation(annotation)
def generateLabel(series, item, lastItemIndex):
	x = series - 1
	startDate = data.getValueAt(lastItemIndex, 0).getTime()
	endDate = data.getValueAt(item, 0).getTime()
	y = (float(startDate) + float(endDate)) * 0.5
	timeDiff = str((float(endDate) - float(startDate)) / 1000) #Time diff is being calculated here, but this could be literally anything
	annotation = XYTextAnnotation(timeDiff, x, y) #Timediff string added to chart
	annotation.setPaint(Color.BLACK)
	annotation.setFont(chartComponent.rangeAxisFont)
	plot.addAnnotation(annotation)
for series in range(1, data.columnCount):
	lastItemValue = data.getValueAt(0, series)
	nextItemValue = data.getValueAt(1, series)
	lastItemIndex = 0
	for item in range(1, data.rowCount):
		if lastItemValue != nextItemValue:
			generateLabel(series, item, lastItemIndex)
			if (item + 1) < data.rowCount:
				lastItemValue = nextItemValue
				nextItemValue = data.getValueAt(item + 1, series)
				lastItemIndex = item
			else:
				generateLabel(series, item, lastItemIndex)
		else:
			if (item + 1) < data.rowCount:
				nextItemValue = data.getValueAt(item + 1, series)
			else:
				generateLabel(series, item, lastItemIndex)

```

**Here is the result:**

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/1/510c5aec89c3f64b8366e955d8dca5136ea688b9.png)

**Here is the result zoomed:**

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/f/0fd19c9eb808b653a3dc6ee1d82bb77b085ec532.png)

The script automatically removes all old annotations before applying new ones, so it can be fired as much as needed. I would probably stick this into a custom method and trigger this once when the window opens, and then retrigger it any time the data changes off of a property change event script.

**Edit:** Getting the rangeAxis upper bound is not needed, and it was simply overlooked artifact from the development process. That logic has been removed from the above script

---

_[View the full topic](https://forum.inductiveautomation.com/t/show-tooltiptext-in-foreground-of-the-status-chart-vision/69084)._
