Access to chart zoom data?

Using the classic chart component, a user can draw a box with the mouse on the chart after it is drawn and it will zoom in on the data to allow the user to see more detail of the data.

My question is…after the user zooms in, am I able to get access to the zoom level, or more specifically the relative axes? I would like to be able to know what data the user has zoomed in on so that I can export it as CSV, or even use that data to run another SQL query with constraints.

Thanks!

-narodauhsoj

This should give you the zoomed date range that could be used to build an export query.

chart = event.source.parent.getComponent('Chart')
print chart.getChart().getPlot().getDomainAxis().getMinimumDate()
print chart.getChart().getPlot().getDomainAxis().getMaximumDate()

Dan

Thank you so much!

Where is the reference that contains that kind of stuff?

-narodauhsoj

I’m glad that helped!

Most, if not all, of the chart components in Ignition are based off of the JFreeChart library. I remembered .getChart() from some other forum post here to get the actual JFreeChart object, and from there it’s just surfing through the documentation to find out how to get the axes and their respective values.

You can see what classes you are working with using .getClass()

print chart.getChart().getClass()
print chart.getChart().getPlot().getClass()
print chart.getChart().getPlot().getDomainAxis().getClass()

The class names don’t exactly match JFreeChart, likely because Ignition uses wrapper objects to allow bindings, etc. I may not even be looking at the correct classes (I’m not really a java guy, so I have to wing it), but it’s usually close enough to figure it out. I assumed these were the corresponding classes:

object returned from getChart()
http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/JFreeChart.html

object returned from getChart().getPlot()
http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/plot/Plot.html
subclass:
http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/plot/XYPlot.html

object returned from getChart().getPlot().getDomainAxis().
http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/axis/ValueAxis.html
subclass:
http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/axis/DateAxis.html

Dan

1 Like