Move the xTrace to synchronize with another chart

Ignition 8.1.25 Vision

I have 2 charts one above the other in separate containers that share the same x axis range values 1-x.

I am trying to use a property change event on the top chart selectedXValue to move the xTrace on the lower chart so they are both looking at the same x value at the same time. The property change is straight forward to get the xTrace value from the top and I am calling a custom function on the lower chart to set that x value on the xTrace but it isn't moving the bar at all.

I have tried several different approaches to using the pixel value but that is probably too difficult since I have subplots on the lower chart and sometimes the y axis width varies depending if there is data in each subplot.

Here is the code on the lower chart custom method that doesn't do anything. I have also tried repainting and refreshing the datasets afterward and still nothing. Anyone know how I can synchronize these 2 chart xTrace values?

	# Get the selected X value from the first chart
	selectedXValue = xPos
		
	# Function to set the X-Trace value on the second chart
	def setXTraceValue(chart, xValue):
	    # Assuming the chart has an xTraceValue property
	    chart.xTraceValue = xValue
	
	# Set the X-Trace value on the second chart
	setXTraceValue(self, selectedXValue)

Um, ..., why aren't you creating everything as one chart with sub-plots? Which chart type component is that?

Great question but unrelated to my question, I had considered doing that awhile back but I separated them because I have a container to the right of this one with 1-4 histograms in it and I wanted them to line up.

I don't have the ability to make this a single chart now, and I believe the main issue that preventing me from going down that road was I am having a variable number of subplots depending on machine type.

Both charts are just regular charts.

If anyone needs this, I ended up figuring it out.
Use a property change script of the first Chart's selectedXValue to call this custom method on the second chart.

Here is that method:

	#Get the chart's XYPlot
	plot = self.getChart().getPlot()
	
	#Get the X-axis (ValueAxis)
	xAxis = plot.getDomainAxis()
	
	#Retrieve the data area (plot area) from ChartRenderingInfo
	plotArea = self.chartRenderingInfo.getPlotInfo().getDataArea()
	
	#Assume targetXValue is the X value you want to click
	targetXValue = selX  # Example value
	
	#Convert the target X value to Java2D pixel position using the X-axis
	pixelPositionX = xAxis.valueToJava2D(targetXValue, plotArea, plot.getDomainAxisEdge())
	
	from java.awt.event import MouseEvent
	
	evt = MouseEvent(self, # which
			MouseEvent.MOUSE_CLICKED, # what
			10, # when
			0, # no modifiers
			int(pixelPositionX), 10, # where: at (pixelPositionX, 10) - go to the corresponding X value in the chart
			1, # only 1 click
			False) # not a popup trigger
	
	self.dispatchEvent(evt)
1 Like