# Cannot add custom colors to Power Chart pens generated by script

**URL:** <https://forum.inductiveautomation.com/t/cannot-add-custom-colors-to-power-chart-pens-generated-by-script/79900>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [October 1, 2023, 6:17pm UTC](https://forum.inductiveautomation.com/t/cannot-add-custom-colors-to-power-chart-pens-generated-by-script/79900 "2023-10-01T18:17:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrei\_Matei](https://avatars.discourse-cdn.com/v4/letter/a/91b2a8/32.png) [@Andrei\_Matei](https://forum.inductiveautomation.com/u/Andrei_Matei)\
**Post date:** [October 1, 2023, 6:17pm UTC](https://forum.inductiveautomation.com/t/cannot-add-custom-colors-to-power-chart-pens-generated-by-script/79900/1 "2023-10-01T18:17:59Z")

</div>

Hi all,

I want to add pens to a Power Chart via a script, I needed to recreate the tag browser because I mapped all the tags with a script as well and the naming scheme was not 'operator friendly'.

I got all the pieces right, but I ran into an issue. I cannot add custom colors to the created pens. I created a random RGB hex function that inserted the values into the pen's display -\> styles -\> {mode} -\> color, but it does not recognize it as a `color` class object, just a string, and colors the pen in grey. I tried `rgb(int, int, int)` and `rgba(int, int, int, 1)`, still no luck. If I don't map styles at all in my script, all the created pens default to the same light teal color.

Is there any function / workaround that can allow me to create a color class object in Jython scripting? I have seen something about `system.gui.color` for Vision, but the project is in Perspective. I'm quite stuck here.

Thanks!

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [October 1, 2023, 8:30pm UTC](https://forum.inductiveautomation.com/t/cannot-add-custom-colors-to-power-chart-pens-generated-by-script/79900/2 "2023-10-01T20:30:29Z")

</div>

Perspective color values need to be a recognized CSS color format. Hex works, as does rgb and certain color names.  
The following values _as strings_ should be valid:

1. `#FF0000` (or `#ff0000`)
2. `rgb(255, 0, 0)`
3. `red`

So I would have expected your `rgb` approach to work (although the alpha inclusion has spotty support between browsers).

Avoid `system.gui` package functions as - just as you said - those are scoped for Vision. Also, avoid any expression Color types as those are `Color` Java objects - not CSS-recognized strings.

Could you print out the EXACT values your script is supplying? Please wrap them as strings before they are output from your script.

---

<div class="post-metadata">

**Author:** ![Andrei\_Matei](https://avatars.discourse-cdn.com/v4/letter/a/91b2a8/32.png) [@Andrei\_Matei](https://forum.inductiveautomation.com/u/Andrei_Matei)\
**Post date:** [October 1, 2023, 11:39pm UTC](https://forum.inductiveautomation.com/t/cannot-add-custom-colors-to-power-chart-pens-generated-by-script/79900/3 "2023-10-01T23:39:01Z")

</div>

> [@cmallonee](#):
>
> Could you print out the EXACT values your script is supplying? Please wrap them as strings before they are output from your script.

Thank you for helping!

This is a snippet of the script that I am using:

```auto
def random_rgb(self):
	import random
		
	_red = random.randint(0, 255)
	_green = random.randint(0, 255)
	_blue = random.randint(0, 255)
	rgb_hex = "#{:02x}{:02x}{:02x}".format(_red, _green,_blue)
	
	return rgb_hex.upper()

```

It returns a string, something like `#353A4D` , or `#F557A1`. I have tried basically function with `rgb()` and `rgba()`, with or without the `.upper()` method for hex values, and with or without calling `str(...)` before returning the value.

 ![PowerChartProblems](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/5/a52dddca2795104bf07f69ad71fd29d710874681.png)

I attached a screenshot with a value inserted by the script for one pen creation. It adds them correctly, at least I think and hope so, but it does not recognize it as a `color`, no color picker next to the inserted hex, like the one you get when manually creating a pen by pressing the `+` icon. The Power Chart defaults to the teal color even if the `color` field is populated.

Hope this helps, and thanks again!

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [October 2, 2023, 12:36am UTC](https://forum.inductiveautomation.com/t/cannot-add-custom-colors-to-power-chart-pens-generated-by-script/79900/4 "2023-10-02T00:36:19Z")

</div>

What version of Perspective are you using? I don't see the same behavior when I attempt this with the PowerChart, and I actually see a different property structure: `pens[x].display.styles.normal.stroke.color` (note the "s" in `styles). I'm using the nightly code from last week, so perhaps this is something we resolved at some point in time.

![Screenshot 2023-10-01 at 5.35.39 PM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/9/993998314efc81b199d437a692e64afdaf2401ce.png)

is there any chance you're creating the entire `style` object within your script? This might be the result of a typo in that `styles` property within your script.

---

<div class="post-metadata">

**Author:** ![Andrei\_Matei](https://avatars.discourse-cdn.com/v4/letter/a/91b2a8/32.png) [@Andrei\_Matei](https://forum.inductiveautomation.com/u/Andrei_Matei)\
**Post date:** [October 2, 2023, 7:35am UTC](https://forum.inductiveautomation.com/t/cannot-add-custom-colors-to-power-chart-pens-generated-by-script/79900/5 "2023-10-02T07:35:40Z")

</div>

> [@cmallonee](#):
>
> is there any chance you're creating the entire `style` object within your script? This might be the result of a typo in that `styles` property within your script.

Well, this is embarrassing... This was the issue. Thank you for helping and sorry for wasting your time.

Have a nice day!
