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?
In this example I need to replace PIR_TEMP (etc.) to other value.
Thanks
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?
In this example I need to replace PIR_TEMP (etc.) to other value.
Thanks
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.
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?
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…
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.
Does it rename the first column to Pyro 1
if you hard-code a name like this?
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:
(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.
Your first query work and second too.
I have do as suggested puttin 3times (`)
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 .
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.
if I hard code the value it work
label for column will be like this ‘Härtestrecke / Auslauf Halten’
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:
I suspect there may be a better way to accomplish this. EDIT: See PGriffith’s answer below for a simple way to do #3.
There’s also the 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.
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
from org.jfree.chart import LegendItemCollection, LegendItem
chartLegend = LegendItemCollection()
chartLegend.add(LegendItem("Item1"))
plot = chart.getPlot()
plot.setFixedLegendItems(chartLegend)