Scripting Date/Time difference of X-axis on Easy Chart

I would like to be able to script an action of clicking 2 points on an easy chart which gives the difference in time in minutes from the dates on the x-axis as an integer. I am having trouble on what to include in the script.

It is a royal pain to do this sort of thing with the EasyChart. You’re in luck, though, if you switch to the EasyNoteChart component from the NoteChart Module. In that module’s documentation, you will find enhanced mouse events, where the timestamp that corresponds to the mouse cursor is exposed as event.domainTS.

I would recommend creating a “Start Measure” button alongside the chart, with a custom properties for state (integer), firstTS (date), and deltaMillis (long). The actionPerformed event on the button would look something like this:

event.source.state = 1
event.source.text = 'First Point...'

The mouseClicked event on the EasyNoteChart would look something like this:

btn = event.source.parent.getComponent('Button')
if btn.state == 1:
	btn.firstTS = event.domainTS
	event.source.traceTS = event.domainTS
	btn.state = 2
	btn.text = 'Second Point...'
elif btn.state == 2:
	btn.deltaMillis = event.domainTS.time - btn.firstTS.time
	event.source.traceTS = event.domainTS
	btn.state = 3
	btn.text = 'Measure Complete'

Then place a label that converts and displays the deltaMillis value however you wish. A constant zero expression binding on btn.state, with a constant string “Start Measure” on btn.text would make everything pretty at window open time.

Thanks, I will download a trial and give it a try. If it works, I hope my company would approve the addition of the NoteChart Module. If not, I will need an alternative option using what we already have with the vision module and tag historian. All suggestions are welcome.

Hello pturmel,
I am getting this error when clicking on the Easy Note Chart(trace mode) after activating the Start Measure button :
“Traceback (most recent call last):
File “event:mouseClicked”, line 3, in
AttributeError: ‘java.awt.event.MouseEvent’ object has no attribute ‘domainTS’”

Also could you please clarify the label binding assignment mentioned here " then place a label that converts and displays the deltaMillis value however you wish. A constant zero expression binding on btn.state , with a constant string “Start Measure” on btn.text would make everything pretty at window open time."

Thanks.

What version are you using? That feature was added in September of last year.

The sample code yields milliseconds difference. You want minutes, so you'll have to convert.

I am using NoteChart-1.9.2.1904161922 with Ignition v7.9.9…

Did you replace the EasyChart in that window with the EasyNoteChart ? It is a separate component.

Thanks for replying. I created a new window in the current project to test the Easy Note Chart with a pen tagged. Then I created the button w/ custom properties and actionPerformed from the script above. I added the script for mouseClicked event on EasyNoteChart. After that I created a label with text binding its property to deltaMillis of the button.

@pturmel I am not sure if I sent my reply properly. Have you received it?

Please send a project export to support@automation-pros.com so I can see exactly what is happening.

With Becky’s gracious assistance over the weekend, I was able to identify and fix this bug. Let’s say the domainTS feature wasn’t very popular, as one huge codepath must have never worked. ):

Anyways, fixes for v7.x LTS and v8.0 are available for download from my module sales page.

3 Likes