# Powerchart - Add pens via script

**URL:** <https://forum.inductiveautomation.com/t/powerchart-add-pens-via-script/41041>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [November 30, 2020, 1:02pm UTC](https://forum.inductiveautomation.com/t/powerchart-add-pens-via-script/41041 "2020-11-30T13:02:36Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![oisin.gribben](https://avatars.discourse-cdn.com/v4/letter/o/9d8465/32.png) [@oisin.gribben](https://forum.inductiveautomation.com/u/oisin.gribben)\
**Post date:** [November 30, 2020, 1:02pm UTC](https://forum.inductiveautomation.com/t/powerchart-add-pens-via-script/41041/1 "2020-11-30T13:02:36Z")

</div>

Hi,  
Is there a possible way to add pens to a powerchart via a script.  
e.g list of tagpaths?

---

<div class="post-metadata">

**Author:** ![code\_skin](https://avatars.discourse-cdn.com/v4/letter/c/43a26b/32.png) [@code\_skin](https://forum.inductiveautomation.com/u/code_skin)\
**Post date:** [November 30, 2020, 1:26pm UTC](https://forum.inductiveautomation.com/t/powerchart-add-pens-via-script/41041/2 "2020-11-30T13:26:24Z")

</div>

It’ll be more than just a list of tagpaths, but have a look at the props.pens property.  
props.pens[x].data.source is where the tagpath would go.

---

<div class="post-metadata">

**Author:** ![toddhowden](https://avatars.discourse-cdn.com/v4/letter/t/2acd7d/32.png) [@toddhowden](https://forum.inductiveautomation.com/u/toddhowden)\
**Post date:** [March 23, 2021, 11:39am UTC](https://forum.inductiveautomation.com/t/powerchart-add-pens-via-script/41041/3 "2021-03-23T11:39:55Z")

</div>

Does someone have a script example for creating a loadable list of tags. Not sure how to best handle this but would be a nice feature to make a selectable list of preconfigured tags that can be loaded via a drop down. Thanks,

---

<div class="post-metadata">

**Author:** ![lachguerabdallah](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lachguerabdallah/32/25558_2.png) [@lachguerabdallah](https://forum.inductiveautomation.com/u/lachguerabdallah)\
**Post date:** [March 23, 2021, 11:49am UTC](https://forum.inductiveautomation.com/t/powerchart-add-pens-via-script/41041/4 "2021-03-23T11:49:19Z")

</div>

in the tagpens properties of easy chart, select the cell that contains the path, then in ‘cell update’ you must put the ‘selected string’ property of the drop-down component

---

<div class="post-metadata">

**Author:** ![epsmitas](https://avatars.discourse-cdn.com/v4/letter/e/4af34b/32.png) [@epsmitas](https://forum.inductiveautomation.com/u/epsmitas)\
**Post date:** [March 23, 2021, 12:04pm UTC](https://forum.inductiveautomation.com/t/powerchart-add-pens-via-script/41041/5 "2021-03-23T12:04:08Z")

</div>

Adhoc Trends in Ignition Exchange.

---

<div class="post-metadata">

**Author:** ![edwinfreirec](https://avatars.discourse-cdn.com/v4/letter/e/8edcca/32.png) [@edwinfreirec](https://forum.inductiveautomation.com/u/edwinfreirec)\
**Post date:** [November 6, 2022, 6:16pm UTC](https://forum.inductiveautomation.com/t/powerchart-add-pens-via-script/41041/6 "2022-11-06T18:16:14Z")

</div>

Hi All, I wonder whether anybody has got any progress on adding pens via drop-down component on Power Chart. It seems that each pen should be added by a JSON. Is it correct?  
Thanks.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [November 8, 2022, 1:55pm UTC](https://forum.inductiveautomation.com/t/powerchart-add-pens-via-script/41041/7 "2022-11-08T13:55:24Z")

</div>

You'll need to add an object of this form to the `pens` property:

> **click for code**
>
> ```python
> {
> "name": tag_name,
> "visible": true,
> "enabled": true,
> "selectable": true,
> "axis": "",
> "plot": 0,
> "display": {
> "type": "line",
> "interpolation": "curveLinear",
> "breakLine": true,
> "radius": 3,
> "styles": {
> "normal": {
> "stroke": {
> "color": "#63BEA2",
> "width": 1,
> "dashArray": 0,
> "opacity": 0.8
> },
> "fill": {
> "color": "#63BEA2",
> "opacity": 0.8
> }
> },
> "highlighted": {
> "stroke": {
> "color": "#63BEA2",
> "width": 1,
> "dashArray": 0,
> "opacity": 1
> },
> "fill": {
> "color": "#63BEA2",
> "opacity": 1
> }
> },
> "selected": {
> "stroke": {
> "color": "#63BEA2",
> "width": 1,
> "dashArray": 0,
> "opacity": 1
> },
> "fill": {
> "color": "#63BEA2",
> "opacity": 1
> }
> },
> "muted": {
> "stroke": {
> "color": "#63BEA2",
> "width": 1,
> "dashArray": 0,
> "opacity": 0.4
> },
> "fill": {
> "color": "#63BEA2",
> "opacity": 0.4
> }
> }
> }
> },
> "data": {
> "source": "histprov:provider:/drv:driver:/tag:tag_path",
> "aggregateMode": "default"
> }
> }
> 
> ```

But what do you need that for ? Isn't the tag browser enough ?  
If you want to restrict available tags, keep in mind that the path can be changed through the pen configuration panel to display any tag, so you'll need to also disable it if you want to make sure only pre-selected tags can be displayed.

---

<div class="post-metadata">

**Author:** ![edwinfreirec](https://avatars.discourse-cdn.com/v4/letter/e/8edcca/32.png) [@edwinfreirec](https://forum.inductiveautomation.com/u/edwinfreirec)\
**Post date:** [November 9, 2022, 9:55am UTC](https://forum.inductiveautomation.com/t/powerchart-add-pens-via-script/41041/8 "2022-11-09T09:55:37Z")

</div>

Hi Pascal,

Thanks for your reply. That is good question. Please, let me try to explain the scenario. In essence, the requirement involves some features such as:

- Create/ Manage/ view charts (power charts), select & add tags to the chart, modify pens features. and save the charts. This is ok, as usual work.
- In the creation chart stage, only specific tags will be shown -on the tree-, where visible tags only pertain to its department, which ultimately pertains to the user’s department who is defining/ selecting tags. There is a requirement, where tags pertain to different department (tag department is not a relation one to one to the tag).

Initially, we were thinking to use tag browser, which is fine as long as there aren’t external features (in this case department, which come from a database), that links to tags visibility/ filtering [if our exploration is not wrong]. Therefore, whether we are not wrong, we are intending to do a pre-work (tags, department, user) and show the specific tags on 1) a table or 2) a drop down box, thus these can be appended to a power chart.

I assume that the following statement is more related to the pen availability on the chart rather the tag selection on the tag browser, right?

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

I hope that I have explained clear enough.

Thanks.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [November 9, 2022, 10:06am UTC](https://forum.inductiveautomation.com/t/powerchart-add-pens-via-script/41041/9 "2022-11-09T10:06:16Z")

</div>

That statement meant that in the powerchart, a user can click the little cogwheel on the top right to access a configuration panel, in which he can access pen settings, which has this:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/e/1e82ad41e09cdef784d284b8a11db25d16e1dec7.png)

Changing things there allows users to display other tags, tags that might outside of their scope.

---

<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:** [November 9, 2022, 12:55pm UTC](https://forum.inductiveautomation.com/t/powerchart-add-pens-via-script/41041/10 "2022-11-09T12:55:38Z")

</div>

> [@edwinfreirec](#):
>
> Initially, we were thinking to use tag browser, which is fine as long as there aren’t external features (in this case department, which come from a database), that links to tags visibility/ filtering [if our exploration is not wrong]. Therefore, whether we are not wrong, we are intending to do a pre-work (tags, department, user) and show the specific tags on 1) a table or 2) a drop down box, thus these can be appended to a power chart.

You **can** use an external Tag Browse Tree Component, in conjunction with the filter extension function, to filter the tags. Just not the one that is embedded in the Power Chart. You have yet to explain how the Tag knows what department it belongs to, or how that can be determined other than just "its in a database".

You will also need to hide the Chart Settings as @pascal.fragnoud points out because from there, if a user knows the path to a tag, even one that is outside of their "department" they can access that tag.

Once you have selected a tag, through whatever method, you will need to use a script to add a new pen to the chart.

Link to their other post, with some more details.

> [@Perspective Power Chart: Graphs Config Management in DB/ Tags display in browse tag](https://forum.inductiveautomation.com/t/perspective-power-chart-graphs-config-management-in-db-tags-display-in-browse-tag/65927):
>
> Hi All, In Perspective, Power Chart, it needs to create a specific graphs base on tags selection, which is ok. Moreover, the idea is, these graphs should be saved/ stored for further recalls/ retrieve. I have seen that there is into the Ignition Exchange an Ad Hoc Trends that helps in this functionality (save configuration - [Ignition Exchange | Inductive Automation](https://inductiveautomation.com/exchange/46/overview)). I assume whether there are large number of configured trends-graphs, these can be saved into a data base to storage them, and i…

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [November 9, 2022, 1:04pm UTC](https://forum.inductiveautomation.com/t/powerchart-add-pens-via-script/41041/11 "2022-11-09T13:04:19Z")

</div>

> [@lrose](#):
>
> You will also need to hide the Chart Settings as @pascal.fragnoud points out because from there, if a user knows the path to a tag, even one that is outside of their "department" they can access that tag.

I have this `} .psc-hide_powerchart_tagpath .ia_powerChartComponent __settings__ tab__content div:nth-child(22) { display: none !important; } {} {` in a style class called "hide\_powerchart\_tagpath", that I add to powercharts' styles to hide that tag path thing.  
It can be reverted by the user from the browser's tools, it's simply a matter of disabling the `display: none` style, but we decided it was enough and that we needed the configuration panel enough to take that chance: one would need to know this thing exists, go and find it in the css of the page, remove the property, then figure out the path to tags he shouldn't have access to.

---

<div class="post-metadata">

**Author:** ![edwinfreirec](https://avatars.discourse-cdn.com/v4/letter/e/8edcca/32.png) [@edwinfreirec](https://forum.inductiveautomation.com/u/edwinfreirec)\
**Post date:** [November 9, 2022, 3:16pm UTC](https://forum.inductiveautomation.com/t/powerchart-add-pens-via-script/41041/12 "2022-11-09T15:16:59Z")

</div>

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

Hi Irose, the scope/ features are little bit wider, but in summary, there are two databases, 1) which contains devices name, for us “tags”, and its data that is already stored/ storing in a SQL database from a third party system- 2) an existing - second data base with Departments and Tags assignment. Thus, this information is intended to be append/ bulked to tag historian-Ignition in a new data base (historian). Also, user assignment is intended to be identified in this database.  
Therefore, the idea is by gathering/ checking Ignition TagNames-Users Vs Tags-Department-users from database, permit to display and select tags, create and save charts.

---

<div class="post-metadata">

**Author:** ![Cristian\_Gomez](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cristian_gomez/32/49040_2.png) [@Cristian\_Gomez](https://forum.inductiveautomation.com/u/Cristian_Gomez)\
**Post date:** [June 24, 2023, 3:42pm UTC](https://forum.inductiveautomation.com/t/powerchart-add-pens-via-script/41041/13 "2023-06-24T15:42:38Z")

</div>

Hello Pascal and thank you very much for the contribution, I have a question about how is the syntax to execute the action to add or remove the props.pends object from the script, I am programming a button to add a path of history from a table already configured, what I fata is to add this path to the pen, and likewise remove it, could you please give me an idea, is that so far I am starting on this topic.  
Thank you very much
