Refreshing Classic Chart

How do we refresh the classic chart? I need to re-execute the “configureChart” extension function, or delay the first time that script is run.

Also, the chart’s dataset is not bound to a db query so “system.db.refresh()” doesn’t work.

Play around with the various appearance properties – those trigger regeneration of the JFreeChart IIRC.

I can’t find it here but I could have sworn I read somewhere that sometimes (usually?) that system.db.refresh will work whether or not its a SQL query so it might be worth a shot anyway if you haven’t already.

I have a classic chart that I’m building 3 different data sets for through scripting. To force the chart to redraw after a dataset update, I do the following:

	chart = event.source.parent.getComponent("Chart")
	chart.setDatasetEnabled("Flags", False)
	chart.setDatasetEnabled("Flags", True)

“Flags” is the name of one of the data sets inside the chart. It doesn’t seem to matter which data set you toggle, it redraws them all.

1 Like

Thanks for your input guys. I was able to refresh my chart configuration, specifically the Y Axis range, after my custom properties updated by running this script in another custom method on the root container.

	#Update Y Axis
	Chart = self.getComponent('Chart')
	axes = Chart.getYAxes()
	axis = axes.get('Default Y Axis')
	maxRange = max(self.max,self.setpointHigh)
	minRange = min(self.min,self.setpointLow)
	range = maxRange - minRange
	axis.setLowerBound(minRange - 0.1*range)
	axis.setUpperBound(maxRange + 0.1*range)
	#Refresh Chart
	print "Chart has been updated after Std Dev value changed

This getter and setter for the Chart object was in my Chart’s “configureChart” extension function and because I’m not very familiar with python/object oriented programming I didn’t think I could just paste that code into another script. But you can, and that’s what I did. Works great. I also tried the script that Brian proposed above:

	chart = self.getComponent('Chart')
	chart.setDatasetEnabled("Data", False)
	chart.setDatasetEnabled("Data", True)

But for some reason that only reset my Y-axis about 50% of the time.
Thanks again!

1 Like

Interesting! My Y-axis (several) were never changing, only the pens and X-axis, so I guess I never would have noticed that bug.

Thanks for posting the solution! I don’t remember seeing a createChart() reference in the docs. I’ll keep it in mind if my charts start acting squirrely .

For posterity: System.db.refresh() will cause any binding to re-run, not just database bindings (as the path to the function would imply)


Where do you get documentation on all these chart methods? I am trying to find out if i can individually show/hide series plots inside a dataset, instead of showing / hiding the entire dataset.

And i’m sure there would be many other customization i’d like to do if i knew what was possible…
Ignition documentation just takes you in circles describing the obvious GUI elements and their configuration. Something super helpful like your ‘setDatasetEnabled()’ was only found here on the forums.

The classic chart is an instance of ChartPanel. The EasyChart contains an instance of ChartPanel surrounded by pen control and time control gingerbread.

This old thread may help you, too:

Thanks Phil, can’t seem to find any reference to the “setDatasetEnabled” method there, i have been spending some time looking through the JFreeChart documentation but it is a bit overwhelming. Is the classic chart also a JFreeChart ChartPanel component? I am assuming it is?

So the Classic Chart is a subclass of the JFreeChart’s ChartPanel (note the hierarchy). It adds methods and fields specific to Ignition data management, like setDatasetEnabled().

The topic I linked will help you get started finding what Ignition-supplied classes and properties are involved in any particular case, and the JavaDocs will fill in the blanks (mostly).

Thanks a lot for the explanation Phil, Java still feels like a foreign language to me. I will have to work on a bit of upskilling in that area i think!
And i did find what i wanted in that second link thank you:

public void setSeriesEnabled(java.lang.String dataSetName,
                             java.lang.String seriesName,
                             boolean vis)