# 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:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aiasa21](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@Aiasa21](https://forum.inductiveautomation.com/u/Aiasa21)\
**Post date:** [January 27, 2023, 8:08am UTC](https://forum.inductiveautomation.com/t/show-tooltiptext-in-foreground-of-the-status-chart-vision/69084/1 "2023-01-27T08:08:19Z")

</div>

Good morning,

I would like to show some data, for example the "timeDiff" as shown in the attachment. I can show what I need with the getTooltipText extension, but I would like to have it always in the foreground of every series.

Should be possible?

Thanks for the help

 ![Immagine 2023-01-27 134058](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/9/697fbbf95af93d5024b52171892850f5542fa12b.png)

---

<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:** [January 27, 2023, 12:37pm UTC](https://forum.inductiveautomation.com/t/show-tooltiptext-in-foreground-of-the-status-chart-vision/69084/2 "2023-01-27T12:37:53Z")

</div>

> [@Aiasa21](#):
>
> as shown in the attachment

I don't see the attachment

---

<div class="post-metadata">

**Author:** ![Aiasa21](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@Aiasa21](https://forum.inductiveautomation.com/u/Aiasa21)\
**Post date:** [January 27, 2023, 12:41pm UTC](https://forum.inductiveautomation.com/t/show-tooltiptext-in-foreground-of-the-status-chart-vision/69084/3 "2023-01-27T12:41:29Z")

</div>

Hi Justin, I forgot it 😅

---

<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:** [January 27, 2023, 4:28pm UTC](https://forum.inductiveautomation.com/t/show-tooltiptext-in-foreground-of-the-status-chart-vision/69084/4 "2023-01-27T16:28:44Z")

</div>

Interesting problem. I imagine that you are going to have to add a [StandardXYSeriesLabelGenerator](https://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/labels/StandardXYSeriesLabelGenerator.html) to your plot renderer using the configureChart extension function.

---

<div class="post-metadata">

**Author:** ![Aiasa21](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@Aiasa21](https://forum.inductiveautomation.com/u/Aiasa21)\
**Post date:** [January 30, 2023, 1:20pm UTC](https://forum.inductiveautomation.com/t/show-tooltiptext-in-foreground-of-the-status-chart-vision/69084/5 "2023-01-30T13:20:32Z")

</div>

Ok, thanks for the suggestion!

---

<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 2, 2023, 11:09pm UTC](https://forum.inductiveautomation.com/t/show-tooltiptext-in-foreground-of-the-status-chart-vision/69084/6 "2023-02-02T23:09:17Z")

</div>

Were you ever able to get this working? I've experimented with several approaches to this problem, but so far, I've had no luck.

---

<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

---

<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 21, 2023, 1:54am UTC](https://forum.inductiveautomation.com/t/show-tooltiptext-in-foreground-of-the-status-chart-vision/69084/8 "2023-02-21T01:54:20Z")

</div>

Looking at this, it looks a little silly to me displaying elapsed time in seconds over timespans that cover days or even weeks, so remembering [a function I recently developed for summing timespans in power tables](https://forum.inductiveautomation.com/t/display-sum-of-a-column-at-the-end-of-the-table/68717/6), I figured it could be easily applied to this as well. **If the following function is added to the above script:**

```auto
def format_time(timestamp):
	days = int(timestamp / 86400)
	hours = int((timestamp % 86400) / 3600)
	minutes = int((timestamp % 3600) / 60)
	seconds = int(timestamp % 60)
	output = []
	if days > 0:
		output.append(str(days) + 'd')
	if hours > 0:
		output.append(str(hours) + 'h')
	if minutes > 0:
		output.append(str(minutes) + 'm')
	if seconds > 0:
		output.append(str(seconds) + 's')
	return ' : '.join(output) if output else '0s'

```

**and the** `timeDiff = ` **line is changed from** `str((float(endDate) - float(startDate)) / 1000)` **to** `format_time((float(endDate) - float(startDate)) / 1000)`

**The result will look like this:**

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/7/77a1ccd12869d5d938c895ff5bd6f72038ba3a3e.png)

**Edit:** added missing return statement to function

---

<div class="post-metadata">

**Author:** ![Aiasa21](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@Aiasa21](https://forum.inductiveautomation.com/u/Aiasa21)\
**Post date:** [February 21, 2023, 6:44am UTC](https://forum.inductiveautomation.com/t/show-tooltiptext-in-foreground-of-the-status-chart-vision/69084/9 "2023-02-21T06:44:59Z")

</div>

Hi Justin, I totally forget to answer, sorry.  
I didn't find anything to make it work so I abandon the chart for the moment; thank you very much for your help, the script is crazy and the result is exactly what I need.

In the next days I will make some test on the project, thanks again for your time!
