Different series name and legend entries.

TeeChart for ActiveX, COM and ASP
Yeray
Site Admin
Site Admin
Posts: 9602
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Different series name and legend entries.

Post by Yeray » Mon Nov 09, 2009 11:22 am

Hi Tony,

I was only trying to propose you a way to obtain what you would like to show with the features that TeeChart for AX can offer you at this moment.
At the same time, I'd like to understand the main problem to be able to open a ticket in the wish list explaining it consistently and in as few words as possible. And a code snipped that works around a problem usually is a good way to do it.
Anyway, I'll add to the wish list the possibility to access to the legend items in AX as in VCL (TA05014542):

Code: Select all

Chart1.Legend.Item[0].Text:='custom text';
And thank you for your time.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

TonyVSUK
Advanced
Posts: 163
Joined: Wed Mar 01, 2006 12:00 am

Re: Different series name and legend entries.

Post by TonyVSUK » Mon Nov 09, 2009 11:32 am

Yeray wrote: I was only trying to propose you a way to obtain what you would like to show with the features that TeeChart for AX can offer you at this moment.
At the same time, I'd like to understand the main problem to be able to open a ticket in the wish list explaining it consistently and in as few words as possible. And a code snipped that works around a problem usually is a good way to do it.
I agree. In my case though, it is going to be a lot of work to code something that will work all the time (eg, when users add series, re-order existing ones, change series types etc). I would sooner have the functionality in my application disabled for now rather than show incorrect legend entries. I just don't want you to waste any time developing a work-around.
Anyway, I'll add to the wish list the possibility to access to the legend items in AX as in VCL (TA05014542):

Code: Select all

Chart1.Legend.Item[0].Text:='custom text';
Thanks. This would solve all my problems at the moment.

PS. Is there a way of calling the VCL version from Microsoft Visual C++?

Yeray
Site Admin
Site Admin
Posts: 9602
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Different series name and legend entries.

Post by Yeray » Mon Nov 09, 2009 2:25 pm

Hi Tony,

Another possibilities of workarounds you could try:
- To have dummy series with as many points as items you want to show in the legend, set the "real" series to not be displayed in the legend. With that you'll be able to change the dummy series' labels and that will influence directly in the legend items.

- Drawing rectangles and text directly to the canvas to create your own custom legend.
TonyVSUK wrote:PS. Is there a way of calling the VCL version from Microsoft Visual C++?
I'm afraid that no. TeeChart VCL is designed for working with Borland/CodeGear/Embarcadero environments. They have a C++ IDE which is C++ Builder where TeeChart VCL is fully supported.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Yeray
Site Admin
Site Admin
Posts: 9602
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Different series name and legend entries.

Post by Yeray » Tue May 04, 2010 3:17 pm

Hi Tony,

Regarding the (TA05014542) problem, I've seen that the legend items are accessible in ActiveX with:

Code: Select all

Private Sub Form_Load()
  TChart1.AddSeries scPoint
  TChart1.Series(0).FillSampleValues 25
  
  With TChart1.Legend
    .ColumnWidthAuto = False
    .ColumnWidths(0) = 100
    TChart1.Environment.InternalRepaint
    .Items.Items(0).Text = "hello"
    .Items.Items(1).Text = "world"
  End With
End Sub
Could you please confirm it?
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

TonyVSUK
Advanced
Posts: 163
Joined: Wed Mar 01, 2006 12:00 am

Re: Different series name and legend entries.

Post by TonyVSUK » Tue May 04, 2010 3:52 pm

This does not really help much as it is not that different to OnLegendGetText. It relies on knowing the order of the series beforehand to set the labels.

Once I hide a series from the legend, this method fails just like OnLegendGetText, and if a user re-orders series at runtime, they end up with incorrectly labelled series. Without capturing every add/remove/move/sort/function/etc series events, I cannot keep track of the contents of the legend. This is why I've been asking for the ability to set the legend entry with the series, that way there can be no confusion about what appears in the legend and the graph. I cannot risk a graph being labelled with one thing and showing another.

Once you start mixing hidden series with the ability to re-order/add/remove/sort/add function/etc, this causes no end of problems.

Yeray
Site Admin
Site Admin
Posts: 9602
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Different series name and legend entries.

Post by Yeray » Wed May 05, 2010 9:45 am

Hi Tony,

I'm afraid that the only modifiable string in a series is the title and the value labels. I think that the better solution four you would be the implementation of the ticket (TA05010743, I've incremented it's priority) that demands the implementation of the series' property "tag". This property stores an integer in TeeChart VCL and an object in TeeChart for .NET. If it would be an object, you could add your series' string (different to the title) and you could use OnGetLegendText to draw this string. If it would be an integer, you could store an index to an array of strings and work the same way.
When the Tag property will be available, you will be able to do this:

Code: Select all

Private Sub Form_Load()
  TeeCommander1.Chart = TChart1

  TChart1.AddSeries scArea
  TChart1.AddSeries scLine
    
  TChart1.Series(0).FillSampleValues
  TChart1.Series(1).FillSampleValues
  
  TChart1.Series(0).Title = "Area Series"
  TChart1.Series(1).Title = "Line Series"
  
  TChart1.Series(0).Tag = "AreaTag"
  TChart1.Series(1).Tag = "LineTag"
  
  TChart1.Legend.LegendStyle = lsSeries
End Sub

Private Sub TChart1_OnGetLegendText(ByVal LegendStyle As Long, ByVal ValueIndex As Long, LegendText As String)
  LegendText = TChart1.Series(ValueIndex).Tag
End Sub
Or, this if the Tag is an integer:

Code: Select all

Dim SeriesStrings() As String
Dim NumEls As Integer

Private Sub Form_Load()
  TeeCommander1.Chart = TChart1

  NumEls = 0

  TChart1.AddSeries scArea
  TChart1.AddSeries scLine
    
  TChart1.Series(0).FillSampleValues
  TChart1.Series(1).FillSampleValues
  
  TChart1.Series(0).Title = "Area Series"
  TChart1.Series(1).Title = "Line Series"

  TChart1.Legend.LegendStyle = lsSeries
End Sub

Private Sub TChart1_OnAddSeries(ByVal SeriesIndex As Long)
  ReDim Preserve SeriesStrings(NumEls + 1) As String
  SeriesStrings(NumEls) = "Series " + Str$(SeriesIndex)
  TChart1.Series(SeriesIndex).Tag = SeriesIndex
  NumEls = NumEls + 1
End Sub

Private Sub TChart1_OnGetLegendText(ByVal LegendStyle As Long, ByVal ValueIndex As Long, LegendText As String)
  LegendText = SeriesStrings(TChart1.Series(ValueIndex).Tag)
End Sub
Please, see the attached example in delphi, where the Tag property is an integer:
legend_with_tag.zip
(2.04 MiB) Downloaded 823 times
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

TonyVSUK
Advanced
Posts: 163
Joined: Wed Mar 01, 2006 12:00 am

Re: Different series name and legend entries.

Post by TonyVSUK » Wed May 05, 2010 10:10 am

I don't have Delphi (I only use MS C++, but VB for quick demos).

I still cannot see this working though. If we look at this,

Private Sub TChart1_OnGetLegendText(ByVal LegendStyle As Long, ByVal ValueIndex As Long, LegendText As String)
LegendText = SeriesStrings(TChart1.Series(ValueIndex).Tag)
End Sub

If I have two series, and then hide series(0), ValueIndex will be zero when it is passed to OnLegendGetText. I will get the "tag" for series(0) even though I actually want the tag for series(1). The "ValueIndex" refers to the entry in the legend, which is not the same as the series number if I have hidden series.

Does that make sense? I really cannot see a way to make this work correctly using OnLegendGetText.

Yeray
Site Admin
Site Admin
Posts: 9602
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Different series name and legend entries.

Post by Yeray » Wed May 05, 2010 2:06 pm

Hi Tony,

Please take a look at this attempt. I know you are not interested in Delphi. But as you know, the AX version is a COM wrapper from the VCL one. So, the things that are possible in VCL, may be also possible in an AX future version.

This is what I've changed in the example above to avoid the hidden series:

Code: Select all

procedure TForm1.Chart1GetLegendText(Sender: TCustomAxisPanel;
  LegendStyle: TLegendStyle; Index: Integer; var LegendText: string);
var i, ActiveSeriesCount: Integer;
begin
  i:=0;
  ActiveSeriesCount:=0;

  while ((not Chart1[i].Active) or (ActiveSeriesCount<>Index)) do
  begin
    if Chart1[i].Active then ActiveSeriesCount:=ActiveSeriesCount+1;
    i:=i+1;
  end;

  LegendText:=SeriesStrings[Chart1[i].Tag];
end;
Also note that in this delphi examples I'm sending the sources but also the exe. So you should be able to run them and see if they fit your needs.
Attachments
legend_with_tag.zip
(2.04 MiB) Downloaded 792 times
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

TonyVSUK
Advanced
Posts: 163
Joined: Wed Mar 01, 2006 12:00 am

Re: Different series name and legend entries.

Post by TonyVSUK » Wed May 05, 2010 2:56 pm

Thanks. The code makes sense, but I still cannot guarantee it working under all circumstances.

I want to avoid OnLegendGetText at all costs. For me it just does not work. It would be fine if in addition to the legend entry index it also passed in the series index, but it does not work this way. I really cannot see the point in the function the way it works at the moment, as the legend entry does not directly relate to a specific series (well it does, but only in the simplest of cases).

The big problem which stops me implementing the workaround you suggest is keeping the SeriesStrings[] array synchronised with the actual list of series. In my app, the user can change the contents of graphs at runtime, and in addition add trend lines, bounds, etc, plus re-order series (which I do not believe I can capture the events for). To keep SeriesStrings[] synchronised is very difficult, at the moment I have to completely redraw the graph on the slightest change just to be sure the series are labelled correctly.

I cannot use OnLegendGetText at the moment as I cannot guarantee that what I write into the legend is related to the correct series.

Tony.

Yeray
Site Admin
Site Admin
Posts: 9602
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Different series name and legend entries.

Post by Yeray » Fri May 07, 2010 2:32 pm

Hi Tony,

It may be interesting to have a SeriesIndex parameter in the OnGetLegendText event. I've added it to the wish list to be studied for inclusion in future releases (TV52014869).
On the other hand, to achieve what you want without using this event I think it would imply a deep redesign on the Legend and it could break compatibility with other customers' applications.
Again, I think that satisfactory solution for you could be the CustomLegendTool, this SeriesIndex parameter in the OnGetLegendText event or the tag property.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

TonyVSUK
Advanced
Posts: 163
Joined: Wed Mar 01, 2006 12:00 am

Re: Different series name and legend entries.

Post by TonyVSUK » Fri May 07, 2010 2:57 pm

Yeray wrote:It may be interesting to have a SeriesIndex parameter in the OnGetLegendText event. I've added it to the wish list to be studied for inclusion in future releases (TV52014869).
This would work fine. It's the only way of telling which series each entry in the legend is referring to. None of the other methods can guarantee that what appears in the legend is correct.

Tony.

Yeray
Site Admin
Site Admin
Posts: 9602
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Different series name and legend entries.

Post by Yeray » Fri May 07, 2010 3:42 pm

Hi Tony,

I'm sure you are right, but you haven't still demonstrated how to break the last workaround example ;)
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

TonyVSUK
Advanced
Posts: 163
Joined: Wed Mar 01, 2006 12:00 am

Re: Different series name and legend entries.

Post by TonyVSUK » Fri May 07, 2010 4:03 pm

Yeray wrote:I'm sure you are right, but you haven't still demonstrated how to break the last workaround example ;)
I can't use tags can I (C++ or VB)?

TonyVSUK
Advanced
Posts: 163
Joined: Wed Mar 01, 2006 12:00 am

Re: Different series name and legend entries.

Post by TonyVSUK » Fri May 07, 2010 5:32 pm

Yeray wrote:On the other hand, to achieve what you want without using this event I think it would imply a deep redesign on the Legend and it could break compatibility with other customers' applications.
I don't follow this. Surely you just add the ability to set a legend entry for each series (one new function). Then if the user has not set a legend entry, the legend displays what it does at the moment (series name). If an entry has been set, use that. No compatibility would be broken (or even affected). You need to go to each series anyway to build the legend, you just need to use a different string (if it has been set).

Yeray
Site Admin
Site Admin
Posts: 9602
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Different series name and legend entries.

Post by Yeray » Mon May 10, 2010 1:31 pm

TonyVSUK wrote:I can't use tags can I (C++ or VB)?
As I explained above, the tag property is available in TeeChart VCL, not yet in TeeChart ActiveX, but it's already in the wish list (TA05010743). Excuse me me if I wasn't clear enough.
TonyVSUK wrote:
Yeray wrote:On the other hand, to achieve what you want without using this event I think it would imply a deep redesign on the Legend and it could break compatibility with other customers' applications.
I don't follow this. Surely you just add the ability to set a legend entry for each series (one new function). Then if the user has not set a legend entry, the legend displays what it does at the moment (series name). If an entry has been set, use that. No compatibility would be broken (or even affected). You need to go to each series anyway to build the legend, you just need to use a different string (if it has been set).
I'm not sure if it will be so easy, but anyway I've added it to the wish list to be investigated for inclusion in future releases (TV52014874).
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply