# Easy char X trace Decimal limit

**URL:** <https://forum.inductiveautomation.com/t/easy-char-x-trace-decimal-limit/75131>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [June 16, 2023, 9:51am UTC](https://forum.inductiveautomation.com/t/easy-char-x-trace-decimal-limit/75131 "2023-06-16T09:51:09Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [June 16, 2023, 9:51am UTC](https://forum.inductiveautomation.com/t/easy-char-x-trace-decimal-limit/75131/1 "2023-06-16T09:51:09Z")

</div>

Hi Guys,

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/f/af96d2dcc9fe1006c0467efa34a0dd9b2983fec9.png)

In easy chart when i select x trace it showing it showing 3 4 digit after decimal.  
**but i want to show only 2 digit after decimal.**  
Is it any way to fix 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:** [June 16, 2023, 11:35am UTC](https://forum.inductiveautomation.com/t/easy-char-x-trace-decimal-limit/75131/2 "2023-06-16T11:35:55Z")

</div>

If you look in the extension functions for the easy chart, there is one specifically for customizing the xTrace labels. You could use python to round the value to two decimal places.

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [June 16, 2023, 12:37pm UTC](https://forum.inductiveautomation.com/t/easy-char-x-trace-decimal-limit/75131/3 "2023-06-16T12:37:12Z")

</div>

Here is code

```auto
def getXTraceLabel(self, chart, penName, yValue):
    # Format the yValue with 2 decimal places
    formatted_y_value = "{:.2f}".format(yValue)

    # Return the formatted value as the x-trace label
    return str(formatted_y_value)

```

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [June 16, 2023, 12:39pm UTC](https://forum.inductiveautomation.com/t/easy-char-x-trace-decimal-limit/75131/4 "2023-06-16T12:39:40Z")

</div>

Can just be this:

```auto
def getXTraceLabel(self, chart, penName, yValue):
    # Format the yValue with 2 decimal places
    return "{:.2f}".format(yValue)

```

No need for the string conversion, it’s already a string.

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [June 16, 2023, 12:40pm UTC](https://forum.inductiveautomation.com/t/easy-char-x-trace-decimal-limit/75131/5 "2023-06-16T12:40:48Z")

</div>

one question date format

Is it correct

```auto
 date_obj = datetime.fromtimestamp(yValue)

    # Format the datetime object as a desired date format
    formatted_date = date_obj.strftime("%Y-%m-%d %H:%M:%S")  
return str(formatted_date)

```

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [June 16, 2023, 12:41pm UTC](https://forum.inductiveautomation.com/t/easy-char-x-trace-decimal-limit/75131/6 "2023-06-16T12:41:43Z")

</div>

I would use `system.date.format()`

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [June 16, 2023, 12:47pm UTC](https://forum.inductiveautomation.com/t/easy-char-x-trace-decimal-limit/75131/7 "2023-06-16T12:47:34Z")

</div>

> [@lrose](#):
>
> `return "{:.2f}".format(yValue)`

tried like this system.date.format(yValue, "yyyy-MM-dd HH:mm:ss")

but getting error

i only want to change the x trace date format

any code idea you have?

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/0/d0287521a2b592a22d97df6a28fd046be1377f0d.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:** [June 16, 2023, 1:06pm UTC](https://forum.inductiveautomation.com/t/easy-char-x-trace-decimal-limit/75131/8 "2023-06-16T13:06:23Z")

</div>

You can also limit your decimals to two places using this setting:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/1/e15a6dda6bd876efe9160519839b173a1d95511d.png)

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [June 16, 2023, 1:07pm UTC](https://forum.inductiveautomation.com/t/easy-char-x-trace-decimal-limit/75131/9 "2023-06-16T13:07:42Z")

</div>

Yes ,thanks i want this to be implemented for normal xy chart also. that y

---

<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:** [June 16, 2023, 1:57pm UTC](https://forum.inductiveautomation.com/t/easy-char-x-trace-decimal-limit/75131/10 "2023-06-16T13:57:24Z")

</div>

> [@prasath.t](#):
>
> tried like this system.date.format(yValue, "yyyy-MM-dd HH:mm:ss")

I have a solution to this question here:

> [@Easy Chart Xtrace & Mark Mode datetime format](https://forum.inductiveautomation.com/t/easy-chart-xtrace-mark-mode-datetime-format/67159/4):
>
> Update: I developed a work around that produces the desired effect by overriding the AutoTickDisplayDateAxis extension of the DateAxis and subsequently customizing the plot's date and time formats. Here is the code: def configureChart(self, chart): from java.text import SimpleDateFormat from org.jfree.chart.axis import DateAxis pureDateFormat = SimpleDateFormat("yyyy/MM/dd") pureTimeFormat = SimpleDateFormat("h:mm:ss a z") dateAxis = DateAxis() plot = chart.getPlot() plot.setDomainA…

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [June 16, 2023, 2:08pm UTC](https://forum.inductiveautomation.com/t/easy-char-x-trace-decimal-limit/75131/11 "2023-06-16T14:08:19Z")

</div>

For reference, your code in the `configureChart` extension function would look like this:

```auto
def configureChart(self, chart):
	from java.text import SimpleDateFormat
	from org.jfree.chart.axis import DateAxis
	dateFormat = SimpleDateFormat("yyyy-MM-dd")
	timeFormat = SimpleDateFormat("HH:mm:ss")
	dateAxis = DateAxis()
	plot = chart.getPlot()
	plot.setDomainAxis(dateAxis)
	plotDateField = plot.getClass().getDeclaredField('dateFormat')
	plotTimeField = plot.getClass().getDeclaredField('timeFormat')
	plotDateField.setAccessible(True)
	plotTimeField.setAccessible(True)
	plotDateField.set(plot,dateFormat)
	plotTimeField.set(plot,timeFormat)
	plotDateField.setAccessible(False)
	plotDateField.setAccessible(False)

```

Good work @justinedwards.jle , I would only say that I would set the Accessibility back to False after mucking about with reflection.

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [June 16, 2023, 2:18pm UTC](https://forum.inductiveautomation.com/t/easy-char-x-trace-decimal-limit/75131/12 "2023-06-16T14:18:40Z")

</div>

> [@lrose](#):
>
> ```auto
> from java.text import SimpleDateFormat
> from org.jfree.chart.axis import DateAxis
> dateFormat = SimpleDateFormat("yyyy-MM-dd")
> timeFormat = SimpleDateFormat("HH:mm:ss")
> dateAxis = DateAxis()
> plot = chart.getPlot()
> plot.setDomainAxis(dateAxis)
> plotDateField = plot.getClass().getDeclaredField('dateFormat')
> plotTimeField = plot.getClass().getDeclaredField('timeFormat')
> plotDateField.setAccessible(True)
> plotTimeField.setAccessible(True)
> plotDateField.set(plot,dateFormat)
> plotTimeField.set(plot,timeFormat)
> plotDateField.setAccessible(False)
> plotDateField.setAccessible(False)
> 
> ```

After using this script i am getting same space in both left and right side of chart

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/e/0e9d2de675fc6285a6618927872396d52c585273.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:** [June 16, 2023, 2:21pm UTC](https://forum.inductiveautomation.com/t/easy-char-x-trace-decimal-limit/75131/13 "2023-06-16T14:21:09Z")

</div>

> [@lrose](#):
>
> set the Accessibility back to False after mucking about with reflection

Not necessary. `.setAccessible()` doesn't change the class, just makes that reference to the field or method (the instance right there) ignore the private/protected/package visibility.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [June 16, 2023, 2:23pm UTC](https://forum.inductiveautomation.com/t/easy-char-x-trace-decimal-limit/75131/14 "2023-06-16T14:23:02Z")

</div>

I had no such artifact in my testing, so I would assume there is something else going on. Also, your date didn't change and it definitely should have.

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [June 16, 2023, 2:28pm UTC](https://forum.inductiveautomation.com/t/easy-char-x-trace-decimal-limit/75131/15 "2023-06-16T14:28:35Z")

</div>

no i tired with test data also  
same thing happening  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/2/7249c6de821a74bfed66c5f2968da681419a7892.png)

see in x axis config also

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/5/d58b3c4c6037a359838301e52ccbe92fe06978ff.png)  
give zero for lower and upper bound

when i disable the script it space is removing

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [June 16, 2023, 2:35pm UTC](https://forum.inductiveautomation.com/t/easy-char-x-trace-decimal-limit/75131/16 "2023-06-16T14:35:03Z")

</div>

Well, the script in the `configureChart` is overwriting the dateAxis with a brand new one, so any configuration you need to do will need to be done there.

So, change the script to this:

```auto
def configureChart(self, chart):
	from java.text import SimpleDateFormat
	from org.jfree.chart.axis import DateAxis
	dateFormat = SimpleDateFormat("yyyy-MM-dd")
	timeFormat = SimpleDateFormat("HH:mm:ss")
	dateAxis = DateAxis()
	dateAxis.lowerMargin = 0
	dateAxis.upperMargin = 0
	plot = chart.getPlot()
	plot.setDomainAxis(dateAxis)
	plotDateField = plot.getClass().getDeclaredField('dateFormat')
	plotTimeField = plot.getClass().getDeclaredField('timeFormat')
	plotDateField.setAccessible(True)
	plotTimeField.setAccessible(True)
	plotDateField.set(plot,dateFormat)
	plotTimeField.set(plot,timeFormat)

```

---

<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:** [June 16, 2023, 2:43pm UTC](https://forum.inductiveautomation.com/t/easy-char-x-trace-decimal-limit/75131/17 "2023-06-16T14:43:16Z")

</div>

Check your console for errors

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [June 16, 2023, 2:45pm UTC](https://forum.inductiveautomation.com/t/easy-char-x-trace-decimal-limit/75131/18 "2023-06-16T14:45:18Z")

</div>

> [@lrose](#):
>
> ```auto
> dateAxis = DateAxis()
> dateAxis.lowerMargin = 0
> dateAxis.upperMargin = 0
> plot = chart.getPlot()
> plot.setDomainAxis(dateAxis)
> plotDateField = plot.getClass().getDeclaredField('dateFormat')
> plotTimeField = plot.getClass().getDeclaredField('timeFormat')
> plotDateField.setAccessible(True)
> plotTimeField.setAccessible(True)
> plotDateField.set(plot,dateFormat)
> plotTimeField.set(plot,timeFormat)
> 
> ```

yes getting this error  
NameError: global name 'dateFormat' is not defined

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [June 16, 2023, 2:46pm UTC](https://forum.inductiveautomation.com/t/easy-char-x-trace-decimal-limit/75131/19 "2023-06-16T14:46:11Z")

</div>

Show your actual code. I suspect you have made a copy paste error.

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [June 16, 2023, 2:48pm UTC](https://forum.inductiveautomation.com/t/easy-char-x-trace-decimal-limit/75131/20 "2023-06-16T14:48:32Z")

</div>

> [@lrose](#):
>
> ```auto
> from java.text import SimpleDateFormat
> from org.jfree.chart.axis import DateAxis
> dateFormat = SimpleDateFormat("yyyy-MM-dd")
> timeFormat = SimpleDateFormat("HH:mm:ss")
> dateAxis = DateAxis()
> dateAxis.lowerMargin = 0
> dateAxis.upperMargin = 0
> plot = chart.getPlot()
> plot.setDomainAxis(dateAxis)
> plotDateField = plot.getClass().getDeclaredField('dateFormat')
> plotTimeField = plot.getClass().getDeclaredField('timeFormat')
> plotDateField.setAccessible(True)
> plotTimeField.setAccessible(True)
> plotDateField.set(plot,dateFormat)
> plotTimeField.set(plot,timeFormat)
> 
> ```

correct copy paste issue. cleared now thanks

[Next page](https://forum.inductiveautomation.com/t/easy-char-x-trace-decimal-limit/75131.md?page=2)
