Change series color of chart from script

Hello, is it possible to change the series colors of a Chart object from a script? ie. a way to control the colors of the plotted data from a script?

Yes, the series color property is just a color array. Here is how you can set it from a button:from java.awt import Color colors = [Color.green, Color.yellow, Color.red, Color.blue, Color.orange, Color.magenta, Color.gray] event.source.parent.getComponent('Chart').seriesColors = colors

1 Like

I seem to be missing something, perhaps the identifier for the dataset or something. Iā€™m getting the following error when trying to recieve the current set of colors:

AttributeError: instance of ā€˜com.inductiveautomation.factorypmi.application.components.PMIChartā€™ has no attribute ā€˜seriesColorsā€™

I am referring to the bar chart component since it has a property called Series Colors. The classic chart doesnā€™t expose the series colors as a property. You can use the following code for your classic chart:from java.awt import Color colors = [Color.green, Color.yellow, Color.red, Color.blue, Color.orange, Color.magenta, Color.gray] chart = event.source.parent.getComponent('Chart') chart.getDynamicProps().get("Data").getRenderer().setSeriesColors(colors) chart.createChart()Just replace the ā€œDataā€ with your dataset you want to change the series colors on.

1 Like

I am running Ignition 7.5.5 and using your script for changing seriesColor on a bar graph component results in an error saying ā€˜seriesColorsā€™ is no attribute.

It should work, are you sure youā€™re getting back the correct bar chart component when using getComponent()?

Your right, James.
Thanks.