# Help building a custom XTraceLabel on a chart

**URL:** <https://forum.inductiveautomation.com/t/help-building-a-custom-xtracelabel-on-a-chart/9843>\
**Category:** Ignition\
**Created:** [March 26, 2015, 2:58pm UTC](https://forum.inductiveautomation.com/t/help-building-a-custom-xtracelabel-on-a-chart/9843 "2015-03-26T14:58:30Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![a344254](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@a344254](https://forum.inductiveautomation.com/u/a344254)\
**Post date:** [March 26, 2015, 2:58pm UTC](https://forum.inductiveautomation.com/t/help-building-a-custom-xtracelabel-on-a-chart/9843/1 "2015-03-26T14:58:30Z")

</div>

I have an Easy Chart displaying history tags from my database. The values are all numerical obviously, but what I want to be able to do is when I display an X Trace or Mark on the chart is display some text from another historical tag - like the name of the recipe I was running at that moment in time. If it can’t be done in the X Trace or Mark window, can it be done in a separate label outside of the chart, but still based on the point in time that I pick on the chart?

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/5/5367ea87609cf9230c9ce7276537dcb2226cfaa8.png)

---

<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:** [March 26, 2015, 5:06pm UTC](https://forum.inductiveautomation.com/t/help-building-a-custom-xtracelabel-on-a-chart/9843/2 "2015-03-26T17:06:44Z")

</div>

I believe chart.getSelectedXValue() is what you are looking for.

---

<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:** [March 26, 2015, 5:09pm UTC](https://forum.inductiveautomation.com/t/help-building-a-custom-xtracelabel-on-a-chart/9843/3 "2015-03-26T17:09:53Z")

</div>

Its also bindable as {…selectedXValue}

---

<div class="post-metadata">

**Author:** ![a344254](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@a344254](https://forum.inductiveautomation.com/u/a344254)\
**Post date:** [March 27, 2015, 7:25pm UTC](https://forum.inductiveautomation.com/t/help-building-a-custom-xtracelabel-on-a-chart/9843/4 "2015-03-27T19:25:21Z")

</div>

The “chart” or “self” objects don’t appear to have that property. I get the error “AttributeError: ‘org.jfree.chart.JFreeChart’ object has no attribute ‘getSelectedXValue’”

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

---

<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:** [March 31, 2015, 1:00am UTC](https://forum.inductiveautomation.com/t/help-building-a-custom-xtracelabel-on-a-chart/9843/5 "2015-03-31T01:00:24Z")

</div>

It would be self.getSelectedXValue() in the custom script. It does not show up in the property pane of the designer, but does show up as a bindable property when setting a binding elsewhere. At least in version 7.7.2.

As a quick example, place a simple label in the same container as your chart. Bind the ‘text’ property of the label to your chart’s ‘selected X Value’ property. Then test your window and set the chart to X-Trace mode and click where there’s data.

---

<div class="post-metadata">

**Author:** ![a344254](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@a344254](https://forum.inductiveautomation.com/u/a344254)\
**Post date:** [March 31, 2015, 2:12pm UTC](https://forum.inductiveautomation.com/t/help-building-a-custom-xtracelabel-on-a-chart/9843/6 "2015-03-31T14:12:23Z")

</div>

OK thanks - I just tested that and while that works, that just gives me the X value (in this case the date). I want to get a value from either another non-displaying pen (because it’s text and not a number) or from the database for this point in time. If you know how I can accomplish that I would appreciate the help, and also appreciate the help so far.

Thanks

---

<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:** [March 31, 2015, 6:54pm UTC](https://forum.inductiveautomation.com/t/help-building-a-custom-xtracelabel-on-a-chart/9843/7 "2015-03-31T18:54:20Z")

</div>

Ok. So you need another level of indirection. Use the selectedXValue in a binding for a custom ‘where’ property that forms the WHERE clause for your database, then include that property in a SQL query binding to deliver the text you want.

You’ll want the custom where property to be ‘false’ when the selectedXValue contains an empty string, and something like “t\_stamp = ‘{…selectedXValue}’” when not empty. The final SQL Query binding should then have a fallback for no result that suits your display.

---

<div class="post-metadata">

**Author:** ![a344254](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@a344254](https://forum.inductiveautomation.com/u/a344254)\
**Post date:** [April 1, 2015, 7:07pm UTC](https://forum.inductiveautomation.com/t/help-building-a-custom-xtracelabel-on-a-chart/9843/8 "2015-04-01T19:07:24Z")

</div>

Ignition support was able to help me get a working solution by putting this code in my getXTraceLabel function.

```
tags = ["PC01/Windup/1/W1 Specname"]
if self.selectedXValue and str(self.selectedXValue) != '1969-12-31 19:00:00':
	data = system.tag.queryTagHistory(paths=tags, startDate = self.selectedXValue, endDate=self.selectedXValue)
	if data.rowCount > 0:
		return penName + ": " + str(yValue) + "\nSpec: " + str(data.getValueAt(0,1))
```
