# Change label series value in chart

**URL:** <https://forum.inductiveautomation.com/t/change-label-series-value-in-chart/20341>\
**Category:** Ignition\
**Created:** [October 24, 2018, 4:57am UTC](https://forum.inductiveautomation.com/t/change-label-series-value-in-chart/20341 "2018-10-24T04:57:45Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![SergioS](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@SergioS](https://forum.inductiveautomation.com/u/SergioS)\
**Post date:** [October 24, 2018, 4:57am UTC](https://forum.inductiveautomation.com/t/change-label-series-value-in-chart/20341/1 "2018-10-24T04:57:45Z")

</div>

Good morning at all,  
I have create a chart and now i need to replace labels of series.  
I don’t arrive to find properties for this.

Please can you help me?

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/f/f8dda4d7518656c379458f822f10512e0fb93c10.png)

In this example I need to replace PIR\_TEMP (etc.) to other value.

Thanks

---

<div class="post-metadata">

**Author:** ![StefanGronberg](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/stefangronberg/32/6288_2.png) [@StefanGronberg](https://forum.inductiveautomation.com/u/StefanGronberg)\
**Post date:** [October 24, 2018, 5:10am UTC](https://forum.inductiveautomation.com/t/change-label-series-value-in-chart/20341/2 "2018-10-24T05:10:32Z")

</div>

With the chart i use i change the legend text in the SQL statement like  
SELECT PIR1\_TEMP AS SomethingElse, perhaps there is a better way, but this is how i have done it.

---

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [October 24, 2018, 5:27am UTC](https://forum.inductiveautomation.com/t/change-label-series-value-in-chart/20341/3 "2018-10-24T05:27:26Z")

</div>

Those labels are the column names in the dataset the chart is bound to. There are multiple ways to set those, depending on how you get the dataset. For example, if you’re getting these via SQL Query binding, StefanGronberg’s solution should do the trick. If you’re using a Tag History binding, there’s a Column Name column next to each tag under selected historical tags in the binding dialogue. You can edit the names there. Or are you using another method to fill the dataset for the chart?

---

<div class="post-metadata">

**Author:** ![SergioS](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@SergioS](https://forum.inductiveautomation.com/u/SergioS)\
**Post date:** [October 24, 2018, 5:32am UTC](https://forum.inductiveautomation.com/t/change-label-series-value-in-chart/20341/4 "2018-10-24T05:32:30Z")

</div>

StefanGronberg and witman, i’m agree with you…

my problem is that label are a query on SQL like this :

sELECT [dbo].[PIROMETRI].DATE\_TIME as t\_stamp  
,[dbo].[PIROMETRI].PIR1\_TEMP as (SELECT [Description] FROM [HES\_TURNI].[dbo].[ParamPyro] where [Machine\_AS] = ‘B1’ and [NamePyro] =‘PIR1’)  
,[dbo].[PIROMETRI].PIR2\_TEMP  
,[dbo].[PIROMETRI].PIR3\_TEMP  
,[dbo].[PIROMETRI].PIR4\_TEMP  
,[dbo].[PIROMETRI].PIR5\_TEMP  
FROM [dbo].[PIROMETRI]

where [dbo].[PIROMETRI].ID\_TURNO = 576 and [dbo].[PIROMETRI].LINEA = 1

and this don’t work…

---

<div class="post-metadata">

**Author:** ![StefanGronberg](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/stefangronberg/32/6288_2.png) [@StefanGronberg](https://forum.inductiveautomation.com/u/StefanGronberg)\
**Post date:** [October 24, 2018, 5:51am UTC](https://forum.inductiveautomation.com/t/change-label-series-value-in-chart/20341/5 "2018-10-24T05:51:04Z")

</div>

> [@SergioS](#):
>
> ,[dbo].[PIROMETRI].PIR1\_TEMP as (SELECT [Description] FROM [HES\_TURNI].[dbo].[ParamPyro] where [Machine\_AS] = 'B1' and [NamePyro] ='PIR1')

I have no setup to quickly test similar, but i assume this is the problem.  
I would test adding "AS somethingelse" in the end of the last parentheses.

---

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [October 24, 2018, 5:56am UTC](https://forum.inductiveautomation.com/t/change-label-series-value-in-chart/20341/6 "2018-10-24T05:56:04Z")

</div>

Does it rename the first column to `Pyro 1` if you hard-code a name like this?

```auto
SELECT [dbo].[PIROMETRI].DATE_TIME AS t_stamp
,[dbo].[PIROMETRI].PIR1_TEMP AS [Pyro 1]
,[dbo].[PIROMETRI].PIR2_TEMP
,[dbo].[PIROMETRI].PIR3_TEMP
,[dbo].[PIROMETRI].PIR4_TEMP
,[dbo].[PIROMETRI].PIR5_TEMP
FROM [dbo].[PIROMETRI]
WHERE [dbo].[PIROMETRI].ID_TURNO = 576 AND [dbo].[PIROMETRI].LINEA = 1

```

If so, test this section of your original code to make sure it is returning what you expect for the alias:

```auto
(SELECT [Description] FROM [HES_TURNI].[dbo].[ParamPyro] WHERE [Machine_AS] = 'B1' AND [NamePyro] ='PIR1')

```

Place triple back-ticks (`) on a line before and after code in forum posts to make it easy to read as above.

---

<div class="post-metadata">

**Author:** ![SergioS](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@SergioS](https://forum.inductiveautomation.com/u/SergioS)\
**Post date:** [October 24, 2018, 6:00am UTC](https://forum.inductiveautomation.com/t/change-label-series-value-in-chart/20341/7 "2018-10-24T06:00:27Z")

</div>

Your first query work and second too.

I have do as suggested puttin 3times (`)

```auto
sELECT [dbo].[PIROMETRI].DATE_TIME as t_stamp
	,[dbo].[PIROMETRI].PIR1_TEMP as (SELECT [Description] FROM [HES_TURNI].[dbo].[ParamPyro] where [Machine_AS] = 'B1' and [NamePyro] ='PIR1')
	,[dbo].[PIROMETRI].PIR2_TEMP
	,[dbo].[PIROMETRI].PIR3_TEMP
	,[dbo].[PIROMETRI].PIR4_TEMP
	,[dbo].[PIROMETRI].PIR5_TEMP
  FROM [dbo].[PIROMETRI]

where [dbo].[PIROMETRI].ID_TURNO = 576 and [dbo].[PIROMETRI].LINEA = 1

```

but i have error .

---

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [October 24, 2018, 6:07am UTC](https://forum.inductiveautomation.com/t/change-label-series-value-in-chart/20341/8 "2018-10-24T06:07:00Z")

</div>

What does the second query return? If you hard-code that return value instead of `Pyro 1` in the first query, do you get the same error? What error are you getting?

About the backticks, looks like you have them but maybe not in quite the right place–if you put them on a line by themselves above all your code and then a line by themselves below all your code in your post, it should format your code neatly.

---

<div class="post-metadata">

**Author:** ![SergioS](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@SergioS](https://forum.inductiveautomation.com/u/SergioS)\
**Post date:** [October 24, 2018, 6:08am UTC](https://forum.inductiveautomation.com/t/change-label-series-value-in-chart/20341/9 "2018-10-24T06:08:26Z")

</div>

if I hard code the value it work  
label for column will be like this ‘Härtestrecke / Auslauf Halten’

---

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [October 24, 2018, 8:03am UTC](https://forum.inductiveautomation.com/t/change-label-series-value-in-chart/20341/10 "2018-10-24T08:03:55Z")

</div>

SQL does not allow a subquery in `AS`. If you need variable column names in the SQL query, you would need to use dynamic SQL. One way to get variable column names _without_ dynamic SQL:

1. Add a custom property of type dataset to the chart and put the SQL binding without AS statements for PIR#\_TEMP columns on it.
2. Add another custom property dataset or string for column names with the appropriate SQL binding.
3. Use scripting to create a dataset with the column names from #2 and add the data rows from #1 to it and then write this dataset to the chart’s dataset.

I suspect there may be a better way to accomplish this. EDIT: See PGriffith’s answer below for a simple way to do #3.

---

<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:** [October 24, 2018, 3:14pm UTC](https://forum.inductiveautomation.com/t/change-label-series-value-in-chart/20341/11 "2018-10-24T15:14:36Z")

</div>

There’s also the [`columnRename`](https://docs.inductiveautomation.com/display/DOC79/columnRename) expression function - bring in the data using a query binding on a dataset custom property, then have an expression binding on the chart’s actual data property that uses `columnRename` to achieve the desired result.

---

<div class="post-metadata">

**Author:** ![ethomason](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ethomason/32/43338_2.png) [@ethomason](https://forum.inductiveautomation.com/u/ethomason)\
**Post date:** [October 24, 2018, 3:47pm UTC](https://forum.inductiveautomation.com/t/change-label-series-value-in-chart/20341/12 "2018-10-24T15:47:11Z")

</div>

You can also create your own legend but you’ll need to figure out how to get the colors, or you can loop through the existing legend and change the text in configureChart

```auto
from org.jfree.chart import LegendItemCollection, LegendItem
	
chartLegend = LegendItemCollection()
chartLegend.add(LegendItem("Item1"))

plot = chart.getPlot()
plot.setFixedLegendItems(chartLegend)

```
