You will need to implement a customChartMouseListener class and add it to the ChartPanel. This will give you the access to both Ignition’s nav methods and JFreeCharts methods for getting the data. This isn’t a particularly straight forward process, and you may need to dig around in the JFreeChart api to accomplish your true end goal.
This should be enough to get you started. Place this in the configureChart extension function of the Chart component. Note, that this is written so that only clicking on the data point itself will open the window. It is possible to write the click event in a way that it will calculate the closest data point, but I haven’t done this here.
#NOTE: self is a reference to the invoking component, in the case of a standard chart
#component this is an com.inductiveautomation.factorypmi.application.components.PMIChart
#which inherits from ChartPanel
from org.jfree.chart import ChartMouseListener
class CustomChartMouseListener(ChartMouseListener):
def chartMouseClicked(self,e):
xyItem = e.getEntity() #gets the data entity that was clicked, None if no entity was clicked
if xyItem: #ensure that a data entity was clicked
dataset = xyItem.getDataset()
xValue = dataset.getXValue(xyItem.getSeriesIndex(),xyItem.getItem())
yValue = dataset.getYValue(xyItem.getSeriesIndex(),xyItem.getItem())
system.nav.openWindow('YourPopupWindowClass',{'yValueParameterName':xValue,'yValueParameterName':yValue})
self.addChartMouseListener(CustomChartMouseListener())
It should be noted that there may indeed be a better/cleaner way to do this, though I see no issues with doing it this way.
Also, while working in the designer if you make changes to the configureChart function script, another version of the mouse listener will be added to the chart’s mouseListener list, the previous listeners are not unregistered. You will need to close the display in the designer at which point the component will unregister the listener. This is important because should your change cause and error within the listener object that exception will continue to be thrown even after you have corrected the root cause in the code.
You should be wary that it is possible this code will potentially be called more than 1 time, so do not put any code in the listener that is dependent upon only running once (e.g. database update querys, tag writes, etc.). Also you should minimize the amount of scripting that takes place in the listener, because long running scripts here will lock your GUI.
You may also want to look into the XYAnnotation Subclasses for adding annotations to the Plot. Adding annotations to the Plot is not particularly simple, especially if you are storing them for pulling up later. But they are probably the best way to indicate to your users that a data point has additional information available for it.