# Report - Change timeseries chart legend with script

**URL:** <https://forum.inductiveautomation.com/t/report-change-timeseries-chart-legend-with-script/75396>\
**Category:** Ignition\
**Tags:** scripting, ignition81\
**Created:** [June 22, 2023, 1:54pm UTC](https://forum.inductiveautomation.com/t/report-change-timeseries-chart-legend-with-script/75396 "2023-06-22T13:54:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![flavien](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@flavien](https://forum.inductiveautomation.com/u/flavien)\
**Post date:** [June 22, 2023, 1:54pm UTC](https://forum.inductiveautomation.com/t/report-change-timeseries-chart-legend-with-script/75396/1 "2023-06-22T13:54:51Z")

</div>

Hi,

I create a report chart with pens below :

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

I have list of dictionnaries like [{'key':'value1','title':'my pen title'} , ...]  
How can I dynamically put my pens' titles in the chart legend by script ?

Thanks

---

<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:** [June 22, 2023, 3:38pm UTC](https://forum.inductiveautomation.com/t/report-change-timeseries-chart-legend-with-script/75396/2 "2023-06-22T15:38:08Z")

</div>

You'll need to adjust your pen names via the `configureChart` hook. I'd recommend searching the forum for example code to start from.

---

<div class="post-metadata">

**Author:** ![flavien](https://avatars.discourse-cdn.com/v4/letter/f/f475e1/32.png) [@flavien](https://forum.inductiveautomation.com/u/flavien)\
**Post date:** [June 23, 2023, 7:58am UTC](https://forum.inductiveautomation.com/t/report-change-timeseries-chart-legend-with-script/75396/3 "2023-06-23T07:58:57Z")

</div>

My chart is in a table row which depends on values in a dataset like below :  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/2/92871f506a7e34cb57a4e3b6963c88fcc0394df7.png)  
How can I get my legend variable in chart script ?

---

<div class="post-metadata">

**Author:** ![stevenson](https://avatars.discourse-cdn.com/v4/letter/s/41988e/32.png) [@stevenson](https://forum.inductiveautomation.com/u/stevenson)\
**Post date:** [July 11, 2025, 8:20pm UTC](https://forum.inductiveautomation.com/t/report-change-timeseries-chart-legend-with-script/75396/4 "2025-07-11T20:20:05Z")

</div>

```python
	from org.jfree.chart import JFreeChart
	from org.jfree.chart.plot import XYPlot
	from org.jfree.data.xy import XYSeriesCollection, XYSeries
	plot = chart.getXYPlot()
	dataset = plot.getDataset()
	# Create a new dataset with updated series keys
	newKeysDict = [{'value1':'my pen title'} , ...]
	if dataset is not None and dataset.getSeriesCount() > 0:
	    newDataset = XYSeriesCollection()
	    for i in range(dataset.getSeriesCount()):
            seriesKey = dataset.getSeriesKey(i)            
			newLabel = newKeysDict[seriesKey] # Update the label
			# Create a new series (you'll need to copy data points)
			newSeries = XYSeries(newLabel)
			for j in range(dataset.getItemCount(i)):
			    x = dataset.getXValue(i, j)
			    y = dataset.getYValue(i, j)
			    newSeries.add(x, y) # Add data points
			newDataset.addSeries(newSeries)
	
	    # Set the new dataset to the plot
	    plot.setDataset(newDataset)

```

in case anyone is looking for something similar.
