Different series name and legend entries.
Different series name and legend entries.
Hello all,
I have a situation where I want to call a series one thing (for example, <data item>, <source file>, <axis>), but want something else to appear in the legend (eg, <data item> or some additional text relating to the data).
Is this possible at the moment? I can only seem to set the legend entry to be a certain format, but the text always shows the series title.
Many thanks in advance,
Tony.
I have a situation where I want to call a series one thing (for example, <data item>, <source file>, <axis>), but want something else to appear in the legend (eg, <data item> or some additional text relating to the data).
Is this possible at the moment? I can only seem to set the legend entry to be a certain format, but the text always shows the series title.
Many thanks in advance,
Tony.
Re: Different series name and legend entries.
Hi Tony,
You could use OnGetLegendText to personalize legend's text:
You could use OnGetLegendText to personalize legend's text:
Code: Select all
Private Sub Form_Load()
TeeCommander1.Chart = TChart1
Dim i As Integer
For i = 0 To 5
TChart1.AddSeries scPoint
TChart1.Series(i).FillSampleValues 5
Next i
End Sub
Private Sub TChart1_OnGetLegendText(ByVal LegendStyle As Long, ByVal ValueIndex As Long, LegendText As String)
Select Case ValueIndex
Case 0: LegendText = "My first item"
Case 1: LegendText = "My second item"
Case 2: LegendText = "My third item"
Case 3: LegendText = "My fourth item"
Case 4: LegendText = "My fifth item"
Case 5: LegendText = "My sixth item"
End Select
End Sub
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: Different series name and legend entries.
Thanks for this, I can definitely work with that.
Would it be possible in a future release to allow the editing the legend text in a TChart commander window/dialog?
Tony.
Would it be possible in a future release to allow the editing the legend text in a TChart commander window/dialog?
Tony.
Re: Different series name and legend entries.
Hi Tony,
Yes, we already have in the wish list the possibility to fully customize all the items (number of items, text and legend symbol) to be included in future releases.
Yes, we already have in the wish list the possibility to fully customize all the items (number of items, text and legend symbol) to be included in future releases.
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: Different series name and legend entries.
Is this in version 8.0.0.7? I notice the CLegendItems and CLegend classes, but how would you set the legend entry when adding a series (that is the ideal time to set the legend entry)?Yeray wrote:Hi Tony,
Yes, we already have in the wish list the possibility to fully customize all the items (number of items, text and legend symbol) to be included in future releases.
Many thanks,
Tony.
Re: Different series name and legend entries.
Hi Tony,
Right now you can't manually modify the number of items on the legend. The number of items in the legend will be:
- The number of series in the chart when legendstyle is lsSeries or lsLastValues.
- The number of values in the first series when legendstyle is lsValues.
- The number of groups when legendstyle is lsSeriesGroups.
What you can change is the text of each item that is going to be displayed with OnGetLegendText as said above.
Note that with TeeChart Pro v9 VCL there will be a CustomLegendTool that will allow to customize many other things.
Right now you can't manually modify the number of items on the legend. The number of items in the legend will be:
- The number of series in the chart when legendstyle is lsSeries or lsLastValues.
- The number of values in the first series when legendstyle is lsValues.
- The number of groups when legendstyle is lsSeriesGroups.
What you can change is the text of each item that is going to be displayed with OnGetLegendText as said above.
Note that with TeeChart Pro v9 VCL there will be a CustomLegendTool that will allow to customize many other things.
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: Different series name and legend entries.
That seems like the correct thing to me (and I have no need to change it).Yeray wrote: Right now you can't manually modify the number of items on the legend. The number of items in the legend will be:
All I want to do is create a series, give it a title, and set the legend entry for it at the same time. At the moment I need to create the series, store the legend entries, wait for the graph to draw, and then intercept "OnGetLegendText" to set the legend entries from the previous stored entries. If my users add their own plots, I lose the ability to do this as I have lost the ordering of the displayed series.
A function called "series.SetLegendText" is what I really need.
Does that make sense?
Tony.
Re: Different series name and legend entries.
Hi Tony,
Hmmm... I'm not sure to see the sense of it. In vcl (delphi) it is possible to do:
But I can't see the final difference of using the OnGetLegendText to do (ActiveX, VB6):
Could you please explain the exact steps to reproduce the problem? Maybe an simple example project we can run as-is here and/or some pictures would help us to understand what you have and what would you like to have.
Hmmm... I'm not sure to see the sense of it. In vcl (delphi) it is possible to do:
Code: Select all
Chart1.Legend.Item[0].Text:='custom text';
Code: Select all
Private Sub TChart1_OnGetLegendText(ByVal LegendStyle As Long, ByVal ValueIndex As Long, LegendText As String)
Select Case ValueIndex
Case 0: LegendText = "custom text"
End Select
End Sub
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: Different series name and legend entries.
I'll try and explain.
First, I add some plots to the graph in my code (the format is "variable", "scenario", "axis")
time, scenario 1, LHS
population[US], scenario 1, LHS
population[UK], scenario 1, LHS
And I want to set the legend entries to
Simulation Time for scenario 1, LH Axis
US Population for default scenario
UK population for default scenario
At this point, I can use OnLegendGetText to set the legend entries as I know all of those plots are "mine", and what index they are in the tchart.
Now the user adds their own plot at runtime which is the sum of the two populations. I have no control over what they call the plot. The list of series now looks like this
time, scenario 1, LHS
total population (user generated)
population[US], scenario 1, LHS
population[UK], scenario 1, LHS
I can now only use OnLegendGetText for the first series. As it is, the user generated plot would have the label entry "US Population for default scenario".
Does that make sense? All would be OK if I could set the legend entry for each series rather than use OnLegendGetText.
Tony.
First, I add some plots to the graph in my code (the format is "variable", "scenario", "axis")
time, scenario 1, LHS
population[US], scenario 1, LHS
population[UK], scenario 1, LHS
And I want to set the legend entries to
Simulation Time for scenario 1, LH Axis
US Population for default scenario
UK population for default scenario
At this point, I can use OnLegendGetText to set the legend entries as I know all of those plots are "mine", and what index they are in the tchart.
Now the user adds their own plot at runtime which is the sum of the two populations. I have no control over what they call the plot. The list of series now looks like this
time, scenario 1, LHS
total population (user generated)
population[US], scenario 1, LHS
population[UK], scenario 1, LHS
I can now only use OnLegendGetText for the first series. As it is, the user generated plot would have the label entry "US Population for default scenario".
Does that make sense? All would be OK if I could set the legend entry for each series rather than use OnLegendGetText.
Tony.
Re: Different series name and legend entries.
Hi Tony,
Couldn't you series' titles to be shown in the legend and use OnAddSeries to set a title for the series that the user will create?
Couldn't you series' titles to be shown in the legend and use OnAddSeries to set a title for the series that the user will create?
Code: Select all
Private Sub Command1_Click()
TChart1.AddSeries scLine
End Sub
Private Sub Form_Load()
Dim i As Integer
For i = 0 To 1
TChart1.AddSeries scLine
TChart1.Series(i).FillSampleValues 5
Next i
TChart1.Series(0).Title = "US Population for default scenario"
TChart1.Series(1).Title = "UK Population for default scenario"
End Sub
Private Sub TChart1_OnAddSeries(ByVal SeriesIndex As Long)
If SeriesIndex = 2 Then
TChart1.Series(SeriesIndex).Title = "total population"
TChart1.Series(SeriesIndex).FillSampleValues 5
End If
End Sub
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: Different series name and legend entries.
I would still lose track of which of the plots are "mine" that way (the "population[US], scenario 1, LHS" which identifies the plot as mine is lost).
Re: Different series name and legend entries.
Hi Tony,
Please try to arrange a simple example project we can run as-is to reproduce the problem here and we will see if we can find a solution for you.
Please try to arrange a simple example project we can run as-is to reproduce the problem here and we will see if we can find a solution for you.
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: Different series name and legend entries.
There is a demo project attached to this message (it's very simple).
1. Run the project.
2. Click "Add first batch". Everything is operating normally.
3. Click "Editor". Add a new series, select "Functions" and "Add".
4. New series is now called "Series5".
5. Click "Add 2nd batch".
The legend entries are now not correct.
The only way around this at the moment is to keep a completely separate list of series legend entries, and also monitor OnSeriesAdd. All would be so much easier if you could just call something like "TChart1.Series(0).SetLegendEntry("some value")"
Tony.
1. Run the project.
2. Click "Add first batch". Everything is operating normally.
3. Click "Editor". Add a new series, select "Functions" and "Add".
4. New series is now called "Series5".
5. Click "Add 2nd batch".
The legend entries are now not correct.
The only way around this at the moment is to keep a completely separate list of series legend entries, and also monitor OnSeriesAdd. All would be so much easier if you could just call something like "TChart1.Series(0).SetLegendEntry("some value")"
Tony.
- Attachments
-
- TChartLegendDemo.zip
- (1.84 KiB) Downloaded 894 times
Re: Different series name and legend entries.
Hi Tony,
If I understand well, you want to check if a series was added through the editor or by code at OnGetLegendText. If so, you could use an array to save the index of the series added by code. Take a look at the modifications I made to your code:
If I understand well, you want to check if a series was added through the editor or by code at OnGetLegendText. If so, you could use an array to save the index of the series added by code. Take a look at the modifications I made to your code:
Code: Select all
Option Explicit
Dim MySeries() As Integer
Dim NumEls As Integer
Private Sub Command1_Click()
Dim i As Integer
NumEls = 0
For i = 0 To 4
TChart1.AddSeries scLine
TChart1.Series(i).FillSampleValues 10
Next i
TChart1.Series(0).Title = "Population[US], default, LHS"
TChart1.Series(1).Title = "Population[DE], default, LHS"
TChart1.Series(2).Title = "Population[IE], default, LHS"
TChart1.Series(3).Title = "Population[UK], default, LHS"
TChart1.Series(4).Title = "Population[FR], default, LHS"
End Sub
Private Sub Command2_Click()
TChart1.ShowEditor
'TeeEditor1.ShowEditor
End Sub
Private Sub Command3_Click()
Dim i As Integer
For i = 0 To 1
TChart1.AddSeries scLine
TChart1.Series(TChart1.SeriesCount - 1).FillSampleValues 10
Next i
TChart1.Series(TChart1.SeriesCount - 2).Title = "Population[IT], default, LHS"
TChart1.Series(TChart1.SeriesCount - 1).Title = "Population[ES], default, LHS"
End Sub
Private Sub Command4_Click()
TChart1.Series(0).RefreshSeries
End Sub
Private Sub TChart1_OnAddSeries(ByVal SeriesIndex As Long)
ReDim Preserve MySeries(NumEls + 1) As Integer
MySeries(NumEls) = SeriesIndex
NumEls = NumEls + 1
End Sub
Private Sub TChart1_OnGetLegendText(ByVal LegendStyle As Long, ByVal ValueIndex As Long, LegendText As String)
Dim i, MyIndex, UserCount As Integer
UserCount = -1
MyIndex = -1
For i = 0 To NumEls - 1
If MySeries(i) = ValueIndex Then
MyIndex = i
Else
If MySeries(i) > ValueIndex Then
UserCount = i
Exit For
End If
End If
Next i
If MyIndex <> -1 Then
Select Case MyIndex
Case 0:
LegendText = "US Population for default scenario"
Case 1:
LegendText = "DE Population for default scenario"
Case 2:
LegendText = "IE Population for default scenario"
Case 3:
LegendText = "UK Population for default scenario"
Case 4:
LegendText = "FR Population for default scenario"
Case 5:
LegendText = "IT Population for default scenario"
Case 6:
LegendText = "ES Population for default scenario"
End Select
Else
If UserCount = -1 Then
UserCount = NumEls
End If
LegendText = "user's series nº " + Str$(ValueIndex - UserCount)
End If
End Sub
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: Different series name and legend entries.
No. Ideally, I don't want to even use OnLegendGetText.Yeray wrote: If I understand well, you want to check if a series was added through the editor or by code at OnGetLegendText. If so, you could use an array to save the index of the series added by code. Take a look at the modifications I made to your code:
All I want to do is set the legend entry at the time I create the series. This workaround needs more work as well as I would need to capture if someone re-orders the series (try moving the top series down after adding the user series). All would be solved if there was a function to set the legend entry for a series instead of using OnGetLegendText.
Don't spend any time adding additional code to the demo above. I won't be implementing it, I'll work out some other way of doing what I need to do.