# Chart Component - Subplot background color via scripting

**URL:** <https://forum.inductiveautomation.com/t/chart-component-subplot-background-color-via-scripting/59109>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [May 2, 2022, 9:54am UTC](https://forum.inductiveautomation.com/t/chart-component-subplot-background-color-via-scripting/59109 "2022-05-02T09:54:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nandakumar.g2](https://avatars.discourse-cdn.com/v4/letter/n/cdc98d/32.png) [@nandakumar.g2](https://forum.inductiveautomation.com/u/nandakumar.g2)\
**Post date:** [May 2, 2022, 9:54am UTC](https://forum.inductiveautomation.com/t/chart-component-subplot-background-color-via-scripting/59109/1 "2022-05-02T09:54:16Z")

</div>

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 !

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/3/7337f59e6cd777defc9d4ce8ddbee852c2695749.png)

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [May 2, 2022, 11:47am UTC](https://forum.inductiveautomation.com/t/chart-component-subplot-background-color-via-scripting/59109/2 "2022-05-02T11:47:07Z")

</div>

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.

```auto
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.

---

<div class="post-metadata">

**Author:** ![nandakumar.g2](https://avatars.discourse-cdn.com/v4/letter/n/cdc98d/32.png) [@nandakumar.g2](https://forum.inductiveautomation.com/u/nandakumar.g2)\
**Post date:** [May 6, 2022, 10:53am UTC](https://forum.inductiveautomation.com/t/chart-component-subplot-background-color-via-scripting/59109/3 "2022-05-06T10:53:02Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![nandakumar.g2](https://avatars.discourse-cdn.com/v4/letter/n/cdc98d/32.png) [@nandakumar.g2](https://forum.inductiveautomation.com/u/nandakumar.g2)\
**Post date:** [May 9, 2022, 5:30am UTC](https://forum.inductiveautomation.com/t/chart-component-subplot-background-color-via-scripting/59109/4 "2022-05-09T05:30:33Z")

</div>

@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

---

<div class="post-metadata">

**Author:** ![nandakumar.g2](https://avatars.discourse-cdn.com/v4/letter/n/cdc98d/32.png) [@nandakumar.g2](https://forum.inductiveautomation.com/u/nandakumar.g2)\
**Post date:** [November 14, 2022, 5:49am UTC](https://forum.inductiveautomation.com/t/chart-component-subplot-background-color-via-scripting/59109/5 "2022-11-14T05:49:09Z")

</div>

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()
