Help building a custom XTraceLabel on a chart

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?


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

Its also bindable as {…selectedXValue}

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’”


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.

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

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.

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