# Dynamic pens in reporting chart

**URL:** <https://forum.inductiveautomation.com/t/dynamic-pens-in-reporting-chart/30072>\
**Category:** Ignition\
**Tags:** ignition80\
**Created:** [November 18, 2019, 10:23pm UTC](https://forum.inductiveautomation.com/t/dynamic-pens-in-reporting-chart/30072 "2019-11-18T22:23:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jburt](https://avatars.discourse-cdn.com/v4/letter/j/7bcc69/32.png) [@jburt](https://forum.inductiveautomation.com/u/jburt)\
**Post date:** [November 18, 2019, 10:23pm UTC](https://forum.inductiveautomation.com/t/dynamic-pens-in-reporting-chart/30072/1 "2019-11-18T22:23:45Z")

</div>

Does anybody have any example code or information on how to get started trying to add dynamic pens to a report chart?

I’ve got a historian query that pulls data based on the unit that a report is running for.

if data[‘unit’] == ‘unit 1’:  
historian\_tags = [‘tag1’, ‘tag2’, ‘tag3’]  
else:  
historian\_tags = [‘tag4’, ‘tag5’, ‘tag6’]

historian\_data = system.tag.queryTagHistory(paths=historian\_tags…

The end result would be

pen 1 = list(historian\_data.columnNames)[1]  
pen 2 = list(historian\_data.columnNames)[2]  
pen 3 = list(historian\_data.columnNames)[3]  
… etc

Pens can’t use indirect tags it seems, and I haven’t been able to find any example code for this. I’ve been banging my head against the jfreechart api documentation without any luck.

---

<div class="post-metadata">

**Author:** ![jburt](https://avatars.discourse-cdn.com/v4/letter/j/7bcc69/32.png) [@jburt](https://forum.inductiveautomation.com/u/jburt)\
**Post date:** [November 18, 2019, 10:45pm UTC](https://forum.inductiveautomation.com/t/dynamic-pens-in-reporting-chart/30072/2 "2019-11-18T22:45:15Z")

</div>

This is my current solution in case others are looking to do the same.

```auto
# Get the historian data.
historian_data = system.tag.queryTagHistory(paths=trend_tags,
												startDate=system.date.addMinutes(data['start_event']['calculated_datetime'], -5),#system.date.addMinutes(system.date.now(), -3000),
												endDate=system.date.addMinutes(data['stop_datetime'], 5),#system.date.now(),#
												returnSize=100,
												aggregationMode='Average',
												returnFormat='Wide',
												noInterpolation=False,
												timeout=10000)

# Change the headers on the table to be static.
pyds = system.dataset.toPyDataSet(historian_data)
headers = ['t_stamp']
index = 0
for name in pyds.columnNames:
	if name == 't_stamp':
		continue
	col_name = 'tag' + str(pressure_index)
	index += 1

rows = [[value for value in row] for row in pyds]
data['trend_data'] = system.dataset.toDataSet(headers, rows)

# Add the actual tag names, and static colors assigned to the pens to a table.

legends = {0:[], 1:[], 2:[], 3:[]}
for index, tag_name in enumerate(pyds.columnNames):
	if tag_name == 't_stamp':
		continue
	legends[(index-1) % 4].append([colors[headers[index]], tag_name.strip('TAG_FOLDER/')])
for legend, tags in legends.items():
	data['legend'+str(legend)] = system.dataset.toDataSet(['color', 'tag'], tags)

```

This allows you to have a table, and 4x tables below that ends up looking something like this:

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

---

<div class="post-metadata">

**Author:** ![philipabangan](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/philipabangan/32/19216_2.png) [@philipabangan](https://forum.inductiveautomation.com/u/philipabangan)\
**Post date:** [November 13, 2020, 3:38pm UTC](https://forum.inductiveautomation.com/t/dynamic-pens-in-reporting-chart/30072/3 "2020-11-13T15:38:16Z")

</div>

Does this script go in the configureChart function in the Report Chart? I’ve been unable to successfully run this solution.

Any help is appreciated, thanks.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [November 13, 2020, 3:52pm UTC](https://forum.inductiveautomation.com/t/dynamic-pens-in-reporting-chart/30072/4 "2020-11-13T15:52:09Z")

</div>

That’s a script data source.
