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

**URL:** <https://forum.inductiveautomation.com/t/scripting-date-time-difference-of-x-axis-on-easy-chart/28483>\
**Category:** Ignition\
**Created:** [September 23, 2019, 7:32pm UTC](https://forum.inductiveautomation.com/t/scripting-date-time-difference-of-x-axis-on-easy-chart/28483 "2019-09-23T19:32:21Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![beckya](https://avatars.discourse-cdn.com/v4/letter/b/b5a626/32.png) [@beckya](https://forum.inductiveautomation.com/u/beckya)\
**Post date:** [September 23, 2019, 7:32pm UTC](https://forum.inductiveautomation.com/t/scripting-date-time-difference-of-x-axis-on-easy-chart/28483/1 "2019-09-23T19:32:21Z")

</div>

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.

---

<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:** [September 23, 2019, 9:48pm UTC](https://forum.inductiveautomation.com/t/scripting-date-time-difference-of-x-axis-on-easy-chart/28483/2 "2019-09-23T21:48:28Z")

</div>

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](https://inductiveautomation.com/moduleshowcase/module/automation-professionals-llc-notechart). In that [module’s documentation](https://www.automation-pros.com/notechart/doc/index.html), 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:

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

```

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![beckya](https://avatars.discourse-cdn.com/v4/letter/b/b5a626/32.png) [@beckya](https://forum.inductiveautomation.com/u/beckya)\
**Post date:** [September 24, 2019, 1:05pm UTC](https://forum.inductiveautomation.com/t/scripting-date-time-difference-of-x-axis-on-easy-chart/28483/3 "2019-09-24T13:05:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![beckya](https://avatars.discourse-cdn.com/v4/letter/b/b5a626/32.png) [@beckya](https://forum.inductiveautomation.com/u/beckya)\
**Post date:** [September 26, 2019, 10:17pm UTC](https://forum.inductiveautomation.com/t/scripting-date-time-difference-of-x-axis-on-easy-chart/28483/4 "2019-09-26T22:17:29Z")

</div>

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.

---

<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:** [September 26, 2019, 10:43pm UTC](https://forum.inductiveautomation.com/t/scripting-date-time-difference-of-x-axis-on-easy-chart/28483/5 "2019-09-26T22:43:49Z")

</div>

> [@beckya](#):
>
> object has no attribute ‘domainTS’”

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

> [@beckya](#):
>
> please clarify the label binding

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

---

<div class="post-metadata">

**Author:** ![beckya](https://avatars.discourse-cdn.com/v4/letter/b/b5a626/32.png) [@beckya](https://forum.inductiveautomation.com/u/beckya)\
**Post date:** [September 26, 2019, 11:27pm UTC](https://forum.inductiveautomation.com/t/scripting-date-time-difference-of-x-axis-on-easy-chart/28483/7 "2019-09-26T23:27:48Z")

</div>

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

---

<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:** [September 26, 2019, 11:33pm UTC](https://forum.inductiveautomation.com/t/scripting-date-time-difference-of-x-axis-on-easy-chart/28483/8 "2019-09-26T23:33:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![beckya](https://avatars.discourse-cdn.com/v4/letter/b/b5a626/32.png) [@beckya](https://forum.inductiveautomation.com/u/beckya)\
**Post date:** [September 26, 2019, 11:46pm UTC](https://forum.inductiveautomation.com/t/scripting-date-time-difference-of-x-axis-on-easy-chart/28483/9 "2019-09-26T23:46:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![beckya](https://avatars.discourse-cdn.com/v4/letter/b/b5a626/32.png) [@beckya](https://forum.inductiveautomation.com/u/beckya)\
**Post date:** [September 28, 2019, 4:05pm UTC](https://forum.inductiveautomation.com/t/scripting-date-time-difference-of-x-axis-on-easy-chart/28483/10 "2019-09-28T16:05:32Z")

</div>

> [@pturmel](#):
>
> Did you replace the EasyChart in that window with the EasyNoteChart ? It is a separate component.

> [@beckya](#):
>
> 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?

---

<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:** [September 28, 2019, 4:08pm UTC](https://forum.inductiveautomation.com/t/scripting-date-time-difference-of-x-axis-on-easy-chart/28483/11 "2019-09-28T16:08:56Z")

</div>

Please send a project export to [support@automation-pros.com](mailto:support@automation-pros.com) so I can see exactly what is happening.

---

<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:** [September 30, 2019, 3:10pm UTC](https://forum.inductiveautomation.com/t/scripting-date-time-difference-of-x-axis-on-easy-chart/28483/12 "2019-09-30T15:10:14Z")

</div>

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](https://www.automation-pros.com/modulesales.html).
