# Can I bind pen colors in a Chart to a client tag?

**URL:** <https://forum.inductiveautomation.com/t/can-i-bind-pen-colors-in-a-chart-to-a-client-tag/88656>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [April 10, 2024, 7:29pm UTC](https://forum.inductiveautomation.com/t/can-i-bind-pen-colors-in-a-chart-to-a-client-tag/88656 "2024-04-10T19:29:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tgish](https://avatars.discourse-cdn.com/v4/letter/t/34f0e0/32.png) [@tgish](https://forum.inductiveautomation.com/u/tgish)\
**Post date:** [April 10, 2024, 7:29pm UTC](https://forum.inductiveautomation.com/t/can-i-bind-pen-colors-in-a-chart-to-a-client-tag/88656/1 "2024-04-10T19:29:28Z")

</div>

We've got lots of embedded charts on our new system. I don't want to use the default colours on the chart customizer though, I want to bind each one to a client tag that is storing a colour value. This way, as we put our new windows through testing and review, if the operators decide they don't like the colours, we only have to change it in one client tag instead of opening up the customizer on every single trend to change them. (Note I'm not talking about dynamically changing pen colours based on values or anything, so I don't think scripting is required?)

But it doesn't seem like there is a nice way to bind these colours. the Foreground Color etc. show as a property of the Chart, but the pen colours seem buried in the customizer.

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

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [April 10, 2024, 9:37pm UTC](https://forum.inductiveautomation.com/t/can-i-bind-pen-colors-in-a-chart-to-a-client-tag/88656/2 "2024-04-10T21:37:10Z")

</div>

Scripting is required. My take on it:

Create a dataset tag with pen names and colors.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/d/ed861ef57f16c150eb698aa1b82405603466d775.png)

In the configureChart function of the chart:

```python
	def datasetToDict(dsIn):
		dictOut = {}
		for i in range(dsIn.rowCount):
			dictOut[dsIn.getValueAt(i, 0)] = dsIn.getValueAt(i, 1)
		return dictOut

	colors = datasetToDict(system.tag.readBlocking(['[client]Styles/Chart Color'])[0].value)

	plot = chart.plot
	renderer = plot.renderer
	seriesCount = plot.seriesCount
	#print dir(renderer)
	legends = renderer.legendItems.iterator()
	#for i in legends:
		#print i.label
	
	for i, legend in enumerate(legends):
		renderer.setSeriesPaint(i, colors[legend.label])

```

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

That said, I'd offload this to a project script, and call it with a tag name for a parameter.

---

<div class="post-metadata">

**Author:** ![tgish](https://avatars.discourse-cdn.com/v4/letter/t/34f0e0/32.png) [@tgish](https://forum.inductiveautomation.com/u/tgish)\
**Post date:** [April 10, 2024, 10:22pm UTC](https://forum.inductiveautomation.com/t/can-i-bind-pen-colors-in-a-chart-to-a-client-tag/88656/3 "2024-04-10T22:22:36Z")

</div>

Thanks! and also: Oof! This is when I start regretting our decision to use Ignition...the Java objects are way beyond me. It's frustrating that the foreground color is so easily bound, but not the pen colours.

> Create a dataset tag with pen names and colors.

That's probably more complicated than I need, I already have a dataset that is bound to the historical tags, and every trend has different pens, so I don't want the "global" colours to be linked to pen names. But I'll try and work with the chart.renderer object and see if I can make it just do the colours. So odd that I have to run a script on every chart just to set the colours.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [April 10, 2024, 11:02pm UTC](https://forum.inductiveautomation.com/t/can-i-bind-pen-colors-in-a-chart-to-a-client-tag/88656/4 "2024-04-10T23:02:15Z")

</div>

If you just want to swap out the color array with your own, you can boil it down to four lines of scripting:

```auto
def configureChart(self, chart):
	colors = system.tag.readBlocking(["[client]Colors"])[0].value

	for i in xrange(chart.plot.seriesCount):
		color = colors.getValueAt(i % colors.rowCount, 0)
		chart.plot.renderer.setSeriesPaint(i, color)

```

That's not bad, considering the immense complexity hiding inside the classic Chart component. Note that the Easy Chart, since it guarantees you'll be displaying a pretty formulaic XY chart, has an auto color list property exposed:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/a/8adc1b2b15f239a91fbdf52eb40a9f053084c0fe.png)

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [April 11, 2024, 11:37am UTC](https://forum.inductiveautomation.com/t/can-i-bind-pen-colors-in-a-chart-to-a-client-tag/88656/5 "2024-04-11T11:37:30Z")

</div>

You may also consider using a template, if the charts are similar in use.

My luck usually runs that, if I had given you my original simplified one, similar to Paul's, you would have asked if it could be tied to pen names. 😆

---

<div class="post-metadata">

**Author:** ![tgish](https://avatars.discourse-cdn.com/v4/letter/t/34f0e0/32.png) [@tgish](https://forum.inductiveautomation.com/u/tgish)\
**Post date:** [April 11, 2024, 3:07pm UTC](https://forum.inductiveautomation.com/t/can-i-bind-pen-colors-in-a-chart-to-a-client-tag/88656/6 "2024-04-11T15:07:20Z")

</div>

Ok, got it! Now next challenge, to discover if the background colour of the legend is hiding in here somewhere...  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/8/58f90a8389223efc432471ec401561f2995b9b39.png)

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/0/40c049b957ac1bdf0200690301a977dc3fbfac6c.png)
