Show X-Trace on a chart by default

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:

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:

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