# Reporting Module Timeseries chart - Change label of legend in script

**URL:** <https://forum.inductiveautomation.com/t/reporting-module-timeseries-chart-change-label-of-legend-in-script/64632>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [September 29, 2022, 6:19am UTC](https://forum.inductiveautomation.com/t/reporting-module-timeseries-chart-change-label-of-legend-in-script/64632 "2022-09-29T06:19:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brad\_Smedley](https://avatars.discourse-cdn.com/v4/letter/b/2bfe46/32.png) [@Brad\_Smedley](https://forum.inductiveautomation.com/u/Brad_Smedley)\
**Post date:** [September 29, 2022, 6:19am UTC](https://forum.inductiveautomation.com/t/reporting-module-timeseries-chart-change-label-of-legend-in-script/64632/1 "2022-09-29T06:19:05Z")

</div>

In a report I am building, I am using a timeseries chart and trying to update the label that is used in the legend.  
I am doing this via script because the data that the timeseries chart uses is dynamic, I am basing my solution on this code from another forum post [here](https://forum.inductiveautomation.com/t/dynamic-report-chart-legend-not-hiding-unused-pens/44565/3)

Here is the code I am using to attempt this:

```auto
	# Taken from https://forum.inductiveautomation.com/t/dynamic-report-chart-legend-not-hiding-unused-pens/44565/2
	from org.jfree.chart.renderer.xy import XYLineAndShapeRenderer
	from org.jfree.chart import LegendItem
	plot = chart.getPlot()
	renderer = plot.getRenderer()
	legend = chart.getLegend()
	legenditems = plot.getLegendItems()
	dataset = plot.getDataset()
	
	xlist = range(dataset.getItemCount(0))
	includedLabels=[]
	for col in range(dataset.getSeriesCount()):
		ylist = [dataset.getY(col, row) for row in range(dataset.getItemCount(col))]
		try: 
			if not all(x is None for x in ylist):
				label = legenditems.get(col).getLabel()
				for tank in data['cs_enabledTanks']:
					if label == tank['name']:
						label = tank
				includedLabels.append(label)
		except TypeError:
			pass
			
	class CustomRenderer(XYLineAndShapeRenderer):
		def getLegendItem(self, dataset, series):
			original = renderer.getLegendItem(dataset, series)
			new = LegendItem(
				original.getLabel(),
				original.getDescription(),
				original.getToolTipText(),
				"", #urlText
				original.getShape(),
				original.getLinePaint(), #set fill paint to line paint
				original.getOutlineStroke(),
				original.getOutlinePaint()
			)
			new.setSeriesIndex(series)
			new.setDatasetIndex(dataset)
			return new
		
		def getLegendItems(self):
			collection = XYLineAndShapeRenderer.getLegendItems(self)
			for ds in range(plot.getDatasetCount()):
				for series in range(plot.getSeriesCount()):
					legend = self.getLegendItem(ds, series)
					for i in includedLabels:
						if legend.getLabel() == i['name']:
# legend.setLabel(i['alias']) 
							# setLabel() doesn't exist, I want to change this label to an alias
							collection.add(legend)
			return collection
	
	newRenderer = CustomRenderer(True, False)
	newRenderer.setBaseSeriesVisibleInLegend(True)
	legend.setSources([newRenderer])

```

My problem is that there doesn’t seem to be a setLabel() method on the LegendItem as seen [here](https://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/LegendItem.html).

Does anyone have an idea of how to change the label of a LegendItem through the script and not via the Pen Name in the Chart Options GUI in the property inspector?

---

<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:** [September 29, 2022, 2:35pm UTC](https://forum.inductiveautomation.com/t/reporting-module-timeseries-chart-change-label-of-legend-in-script/64632/2 "2022-09-29T14:35:43Z")

</div>

When you’re creating a new legend item, you can provide whatever string you want - you don’t _have_ to recycle from `original.getLabel()`.

```python
			new = LegendItem(
				original.getLabel(),
				original.getDescription(),
				original.getToolTipText(),
				"", #urlText
				original.getShape(),
				original.getLinePaint(), #set fill paint to line paint
				original.getOutlineStroke(),
				original.getOutlinePaint()
			)

```
