My project uses both Charts and EasyCharts. I received a feature request requiring that I save the user’s preference for chart background color when they use the right-click popup menu to change the color. For Charts, I accomplished this by using the configureChart extension function which is invoked when the right-click popup menu is used.
Unfortunately for EasyCharts, the configureChart function is not called when the user uses the popup menu. Is there another event or hook I can use to execute some code when the user uses the right-click popup menu?
Here’s one approach… maybe a little heavy handed, but the technique could possibly be applied elsewhere:
In Window -> Scripting… -> internalFrameActivated:
from com.inductiveautomation.factorypmi.application.components import PMIEasyChart
from com.inductiveautomation.factorypmi.application.components import PMIChart
charts = project.NewScript.getMatchingComponents([PMIEasyChart, PMIChart], event.source.rootContainer)
for chart in charts:
print chart.plotBackground
# set background color if user has preference saved
In Window -> Scripting… -> visionWindowClosed:
from com.inductiveautomation.factorypmi.application.components import PMIEasyChart
from com.inductiveautomation.factorypmi.application.components import PMIChart
charts = project.NewScript.getMatchingComponents([PMIEasyChart, PMIChart], event.source.rootContainer)
for chart in charts:
print chart.plotBackground
# save user preference if chart is not default white
In Project -> Scripts -> Script Library -> NewScript: (or Global -> Shared if useful)
def getMatchingComponents(componentTypes, rootComponent):
matches = []
if rootComponent is None:
return matches
if hasattr(rootComponent, 'components'):
children = rootComponent.components
for child in children:
matches.extend(getMatchingComponents(componentTypes, child))
if(type(rootComponent) in componentTypes):
matches.append(rootComponent)
return matches
Seems like @phillip.bow has the right idea, just grab the plotBackground when the window closes (or on a timer or something) since it seems fairly involved to get it when it actually changes.
To simplify things though:
ez = event.source.rootContainer.getComponent("Easy Chart")
print ez.plotBackground
Functionality of charts and many components in Ignition is very basic and i don't think anything much will happen. Dashboard and component development community is very active in React JS. I think, Ignition has realized this trend and hence planning to release a new JS visualization module called Perspective. Very good move. Check this topic.
It doesn’t appear you’re getting your question answered. I’ve been working with the JFreeChart library for a few weeks now trying to control whether axes on certain subplots are visible or not. My understanding is the EasyChart is built from the base library JFreeChart, I’m not certain about the Chart component.
You’d have to check it’s properties, and read up on its javadocs to determine what you might have at your disposal.