# Show X-Trace on a chart by default

**URL:** <https://forum.inductiveautomation.com/t/show-x-trace-on-a-chart-by-default/17230>\
**Category:** Ignition\
**Created:** [March 5, 2018, 5:56pm UTC](https://forum.inductiveautomation.com/t/show-x-trace-on-a-chart-by-default/17230 "2018-03-05T17:56:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![cstoica](https://avatars.discourse-cdn.com/v4/letter/c/3be4f8/32.png) [@cstoica](https://forum.inductiveautomation.com/u/cstoica)\
**Post date:** [March 5, 2018, 5:56pm UTC](https://forum.inductiveautomation.com/t/show-x-trace-on-a-chart-by-default/17230/1 "2018-03-05T17:56:50Z")

</div>

Is it possible to show the X-Trace on a chart when the page is loaded (without having to click on the graph)? I set the mode to 4 (self.setMode(4)) but I don’t know how to make the X-Trace to be visible by default.  
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 5, 2018, 6:16pm UTC](https://forum.inductiveautomation.com/t/show-x-trace-on-a-chart-by-default/17230/2 "2018-03-05T18:16:12Z")

</div>

I don’t know of a way to do it with Ignition’s built-in charts. It can be done with the [NoteChart Module](https://inductiveautomation.com/moduleshowcase/module/automation-professionals-llc-notechart) with both the classic NoteChart and the EasyNoteChart by assigning a date/time to the traceTS property with a script. Or possibly bind that to now() to maintain an XTrace of the latest values.  
See the feature list in the [documentation](https://www.automation-pros.com/notechart/doc/index.html).

---

<div class="post-metadata">

**Author:** ![cstoica](https://avatars.discourse-cdn.com/v4/letter/c/3be4f8/32.png) [@cstoica](https://forum.inductiveautomation.com/u/cstoica)\
**Post date:** [March 11, 2018, 11:33pm UTC](https://forum.inductiveautomation.com/t/show-x-trace-on-a-chart-by-default/17230/3 "2018-03-11T23:33:16Z")

</div>

Is there a way to change the X-Trace label color on the classic Note Chart? By default, the label has the same color as the graph, but if light colors are used, it is difficult to see it on the white background. Ideally, I would like to see the labels black (same as the time stamp).  
Can the visibility on the X-Trace be change? One option is to change the trace timestamp so it will be outside of the domain axis, but this won’t work for me.  
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 12, 2018, 2:02am UTC](https://forum.inductiveautomation.com/t/show-x-trace-on-a-chart-by-default/17230/4 "2018-03-12T02:02:48Z")

</div>

> [@cstoica](#):
>
> By default, the label has the same color as the graph, but if light colors are used, it is difficult to see it on the white background.

Unfortunately, no. And no convenient way to change that. Presumably, if the chosen color is hard to read, it'd be hard to see the line, too. Note that the text of the X-Trace value is painted on a partially transparent background, repeating the chart background. That makes the labels more readable when on top of a tangle of lines, but there still has to be _some_ contrast.[quote="cstoica, post:3, topic:17230"]  
One option is to change the trace timestamp so it will be outside of the domain axis, but this won't work for me  
[/quote]  
It has to stay within the chart as all of the outer boundary decorations can be turned off. The chart area itself is the only sure place to put it (along with the value labels).

---

<div class="post-metadata">

**Author:** ![iavor.karakashev](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/iavor.karakashev/32/70482_2.png) [@iavor.karakashev](https://forum.inductiveautomation.com/u/iavor.karakashev)\
**Post date:** [April 26, 2023, 10:56am UTC](https://forum.inductiveautomation.com/t/show-x-trace-on-a-chart-by-default/17230/5 "2023-04-26T10:56:33Z")

</div>

It's a bit hacky, but after self.setMode(4) you can simulate a mouse click on the chart control and the the x-trace will show up:

```auto
from java.awt.event import MouseEvent 
chart = event.source.parent.getComponent('Chart')
evt = MouseEvent(chart, # which
		MouseEvent.MOUSE_CLICKED, # what
		system.date.toMillis( system.date.now() ), # when
		0, #// no modifiers
		5000, 10, # where: at (5000, 10} - go to the latest record in the chart
		1, # only 1 click 
		False); # not a popup trigger
chart.dispatchEvent(evt)

```

---

<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:** [April 26, 2023, 2:30pm UTC](https://forum.inductiveautomation.com/t/show-x-trace-on-a-chart-by-default/17230/6 "2023-04-26T14:30:20Z")

</div>

In an Easy Chart, the xTrace option is more or less directly accessible, so in reality, no mouse mimicking hocus pocus is needed, and in the Classic Chart, the xTrace option can still be set; it just requires a little reflection. Using the componentRunning propertyChange event, it is possible to set either chart type to xTrace mode when the Vision Window is opened. It's always worth noting that in the designer, preview mode must be running when the window is opened to get this event to fire.

**Here is a script that would accomplish this in a Classic Chart:**

```auto
if event.propertyName == 'componentRunning':
	chartComponent = event.source
	xTrace = chartComponent.getClass().getSuperclass().getDeclaredField("xtraceItem")
	xTrace.setAccessible(True)
	xTrace.get(chartComponent).setSelected(True)

```

**Here is a script that would accomplish this in an Easy Chart:**

```auto
if event.propertyName == 'componentRunning':
	chartComponent = event.source
	def getXTraceOption(chartComponent):
		if chartComponent.componentCount > 0:
			for component in chartComponent.getComponents():
				if 'PMIEasyChart$EasyChart' in str(component. __class__ ):
					return component.getPopupMenu().getSubElements()[0].getComponent().getItem(3)
				else:
					xTraceOption = getXTraceOption(component)
					if xTraceOption is not None:
						return xTraceOption
		return None
	xTraceOption = getXTraceOption(chartComponent)
	xTraceOption.setSelected(True)

```

---

<div class="post-metadata">

**Author:** ![john.eichler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/john.eichler/32/24632_2.png) [@john.eichler](https://forum.inductiveautomation.com/u/john.eichler)\
**Post date:** [June 1, 2023, 2:47am UTC](https://forum.inductiveautomation.com/t/show-x-trace-on-a-chart-by-default/17230/7 "2023-06-01T02:47:56Z")

</div>

> [@justinedwards.jle](#):
>
> `def getXTraceOption(chartComponent):`

Old post but very useful. Thank you!
