Chart Component - Subplot background color via scripting

Hello members,

In Vision’s Chart component , I need to change the Subplot background color. Although it is configurable from Plot properties tab (please see image below), I need to change it based on some conditions. So how to access the background color via scripting?

Thanks in advance for the help !

It’s a little involved. When are you wanting to change the color?

Assuming that the type of plot returned by chart.getPlot() is a CombinedDomainXYPlot you can use getSubplots() to get a list of the sub plots. Then on the reference to the plot you want, you call setBackgroundPaint() giving it a Paint type object for the color.

from java.awt import color

supplots = chart.getPlot().getSubplots()
for plot in subplots:
    plot.setBackgroundPaint(Color.red)

What you are actually trying to accomplish (e.g. communicate to the end-user) will dictate where you put that script and may include adding a custom plot change listener, or other mechanisms in order to accomplish your goal. It will also dictate how you go about getting a reference to the chart object.

Honestly, there might be a simpler/better way to achieve your goal.

1 Like

@Irose,

Thank you for the support. The sample script above helped to solve the issue.
Yeah, as you mentioned there might be simpler way as well.

@lrose
Sorry to re-open this subject again.

I implemented changing of subplot background color using “plot.setBackgroundPaint(color)”, but when the subplot is zoomed in/out using right click, this background color gets lost and entire plot background is only visible.

Is there any way to retain the subplot background color even after zoom in / out ?

Thanks in advance for your reply

Hello All,

Just an update. I used below lines along with chart.createChart() which helped to retain the subplots color through scripting

from java.awt import color
chart = event.source.parent.getComponent('Chart')
chart.getPlotProperties()[0].setBackground(Color.red) #0 refers to subplot number
chart.createChart()

1 Like