Use one chart X axis to another chart X axis (datetime Axis)

Hi,

I am using one easy chart and one XY chart
i want tp use the Easy chart X axis to the XY chart

Is there any way to do it?

Are you talking about synchronizing the domain of the first chart to the second chart so if the first chart changes from 10 AM to 10 PM, the second one automatically changes as well?

I mean, you don't want to change the data displayed, just change the times that are displayed?

I can imagine quite a few ways to approach this. If you just want to script it where the charts are synced when the page is opened, you could add this script to your Xy chart's configureChart extension function:

#def configureChart(self, chart):
	from org.jfree.chart.axis import DateAxis
	easyChart = self.parent.getComponent('Easy Chart') #Correct this path, so it matches your chart
	startDate = easyChart.dateRange.startDate.time
	endDate = easyChart.dateRange.endDate.time
	dateAxis = DateAxis()
	dateAxis.setRange(startDate, endDate)
	chart.plot.setDomainAxis(dateAxis)

If you want it to change any time the visible domain is changed on the other chart, you could add this script to your Easy Chart's propertyChange event handler instead of using the above script:

if event.propertyName == 'startDate' or event.propertyName == 'endDate' or event.propertyName == "componentRunning":
	from org.jfree.chart.axis import DateAxis
	otherChart = event.source.parent.getComponent('Chart') #Correct this path, so it matches your chart
	startDate = event.source.dateRange.startDate.time
	endDate = event.source.dateRange.endDate.time
	dateAxis = DateAxis()
	dateAxis.setRange(startDate, endDate)
	otherChart.chart.plot.setDomainAxis(dateAxis)

#The latter script will update the axis when the domain changes and when the chart initially starts running.

1 Like

exactly i want time to change that's it

not getting correct output
script

tested in button mouse clicked
from org.jfree.chart.axis import DateAxis
easyChart = event.source.parent.getComponent('Work Performance')
startDate = easyChart.dateRange.startDate.time
endDate = easyChart.dateRange.endDate.time
print startDate 
print endDate

chartComponent = event.source.parent.getComponent('Chart')
chart = chartComponent.chart
plot = chart.XYPlot
dateAxis = DateAxis()
dateAxis.setRange(startDate, endDate)
plot.setDomainAxis(dateAxis)

output

I just tested it using your script, and it is working correctly for me. There must be something different about my Easy Chart configuration:

I checked but i couldn't find which configuration affecting
For your reference

Easy chart.zip (15.8 KB)

I see the problem; my chart had the wrong kind of plot. In any case, I rewrote your button script to simply grab the domain axis straight from the easy chart and apply it directly to your regular chart.
Here is the script:

def getDomainAxis(easyChart):
	if easyChart.componentCount > 0:
		for component in easyChart.getComponents():
			if 'PMIEasyChart$EasyChart' in str(component.__class__):
				return component.chart.plot.domainAxis
			else:
				domainAxis = getDomainAxis(component)
				if domainAxis is not None:
					return domainAxis
	return None
easyChart = event.source.parent.getComponent('Work Performance')
domainAxis = getDomainAxis(easyChart)
chartComponent = event.source.parent.getComponent('Chart')
chart = chartComponent.chart
plot = chart.XYPlot
plot.setDomainAxis(domainAxis)

Here is the result:

1 Like