Customizing series on legend

TeeChart for ActiveX, COM and ASP
Post Reply
JAV
Newbie
Newbie
Posts: 65
Joined: Thu May 12, 2011 12:00 am

Customizing series on legend

Post by JAV » Wed Aug 17, 2011 6:20 pm

In a nine series graph, we need a legend only for 6 of 9 series, we do not need to display the other three. How can we customize this?

Best regards,

JAV

JAV
Newbie
Newbie
Posts: 65
Joined: Thu May 12, 2011 12:00 am

Re: Customizing series on legend

Post by JAV » Thu Aug 18, 2011 12:49 am

Hello, we just found that grouping series using SeriesGroup could be a way to solve our need, but we have the following issue:
Please refer to Ejecucion1.jpg:
In this graph, the gray series belongs to the group named "PILOTO", the green line to "1", violet line to "2" and blue line to "3", but how can we assign a color to a series group?
and how can we display the color on a legend ?(but one color for each group).

Another issue: Any time that we click on the graphic to regenerate it (in the case we want another random color), the legend doesn't refresh but remains and cumulates with each click. How can the legend be refreshed and cleaned (Ejecucion4.jpg: note how after four clicks we now have the leyend four times).

Best regards,

JAV
Attachments
Ejecucion4.JPG
Ejecucion4.jpg (Second issue)
Ejecucion4.JPG (54.55 KiB) Viewed 11992 times
Ejecucion1.JPG
Ejecucion1.jpg (First issue)
Ejecucion1.JPG (51.33 KiB) Viewed 11977 times

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

Re: Customizing series on legend

Post by Yeray » Thu Aug 18, 2011 2:18 pm

Hello,
JAV wrote:In a nine series graph, we need a legend only for 6 of 9 series, we do not need to display the other three. How can we customize this?
You could use the ShowInLegend property. For example:

Code: Select all

Private Sub Form_Load()  
  TChart1.Aspect.View3D = False

  Dim i As Integer
  For i = 0 To 8
    TChart1.AddSeries scLine
    TChart1.Series(i).FillSampleValues
    
    If i > 5 Then
      TChart1.Series(i).ShowInLegend = False
    End If
  Next i
  
  TChart1.Legend.Alignment = laBottom
  TChart1.Legend.CheckBoxes = True
End Sub
JAV wrote:Hello, we just found that grouping series using SeriesGroup could be a way to solve our need, but we have the following issue:
Please refer to Ejecucion1.jpg:
In this graph, the gray series belongs to the group named "PILOTO", the green line to "1", violet line to "2" and blue line to "3", but how can we assign a color to a series group?
and how can we display the color on a legend ?(but one color for each group).
I'm afraid it's not possible to set a series group legend symbol. Note that a series group can be formed by different series types so TeeChart can't decide what symbol to use.
However, you can always use custom drawing techniques to draw your symbols manually. Something as follows:

Code: Select all

Private Sub Form_Load() 
  TChart1.Aspect.View3D = False

  TChart1.SeriesList.AddGroup "First group"
  TChart1.SeriesList.AddGroup "Second group"
  Dim i As Integer
  For i = 0 To 8
    TChart1.AddSeries scLine
    TChart1.Series(i).FillSampleValues
    
    TChart1.SeriesList.Groups.Items(i Mod 2).Add i
  Next i
  
  TChart1.Legend.Alignment = laBottom
  TChart1.Legend.CheckBoxes = True
  TChart1.Legend.LegendStyle = lsSeriesGroups
End Sub

Private Sub TChart1_OnAfterDraw()
  Dim i As Integer
  For i = 0 To TChart1.SeriesList.Groups.Count - 1
    TChart1.Canvas.Pen.Color = TChart1.SeriesList.Groups.Items(i).Series.Items(0).Color
    TChart1.Canvas.DrawLine TChart1.Legend.Item(i).SymbolRect.Left, TChart1.Legend.Item(i).SymbolRect.Top + 5, TChart1.Legend.Item(i).SymbolRect.Right, TChart1.Legend.Item(i).SymbolRect.Top + 5
  Next i
End Sub
JAV wrote:Another issue: Any time that we click on the graphic to regenerate it (in the case we want another random color), the legend doesn't refresh but remains and cumulates with each click. How can the legend be refreshed and cleaned (Ejecucion4.jpg: note how after four clicks we now have the leyend four times).
I suspect you are recreating the series each time the chart is clicked, without clearing the chart. That's the easier explanation for your "increasing legend" problem. However, I'm not sure if that is really the problem as I haven't seen the project, and I'm not sure either if what you would like to do is to refresh the series data or completely destroy all the series and recreate them.
If you still have problems with this, please try to arrange a simple example project we can run as-is to reproduce the problem here.
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

JAV
Newbie
Newbie
Posts: 65
Joined: Thu May 12, 2011 12:00 am

Re: Customizing series on legend

Post by JAV » Thu Aug 18, 2011 4:54 pm

Hello Yeray:

Thanks for replying. I think your suggestion is good, but in the next line I get the error attached in the picture. What am I doing wrong?

Code: Select all

TChart1.Canvas.DrawLine TChart1.Legend.Item(i).SymbolRect.Left, TChart1.Legend.Item(i).SymbolRect.Top + 5, TChart1.Legend.Item(i).SymbolRect.Right, TChart1.Legend.Item(i).SymbolRect.Top + 5
Regarding the latter point, indeed, I am recreating the series each time the chart is clicked, i don't know how clear the chart. I'm using:

Code: Select all

TChart1.RemoveAllSeries
TChart1.SeriesList.ClearValue
Something I'm doing wrong :oops:

It is possible to change the color of the series without regenerate the graph?

Thanks a lot!

Best regards,

JAV
Attachments
error.jpg
error.jpg (10.89 KiB) Viewed 11917 times

JAV
Newbie
Newbie
Posts: 65
Joined: Thu May 12, 2011 12:00 am

Re: Customizing series on legend

Post by JAV » Thu Aug 18, 2011 6:00 pm

Hello Yeray:

I solved the error attached in the previous message by changing the original code:

Code: Select all

TChart1.Canvas.DrawLine TChart1.Legend.Item(i).SymbolRect.Left, TChart1.Legend.Item(i).SymbolRect.Top + 5, TChart1.Legend.Item(i).SymbolRect.Right, TChart1.Legend.Item(i).SymbolRect.Top + 5
by:

Code: Select all

TChart1.Canvas.DrawLine TChart1.Legend.Item(i).Left - 15, TChart1.Legend.Item(i).Top + 5, TChart1.Legend.Item(i).Left - 5, TChart1.Legend.Item(i).Top + 5
Perhaps the error occurred because I'm working with version 8 and not the last one.

Please, only I need to know how clear the chart, or how to change the color of the series without regenerate the graph?

Thanks a lot!

JAV

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

Re: Customizing series on legend

Post by Yeray » Fri Aug 19, 2011 2:54 pm

Hello JAV,

To change a series color:

Code: Select all

TChart1.Series(0).Color = vbRed
Regarding the cleaning problem, I'm not sure to understand why do you need to remove the series. You don't need to remove all the series and recreate them to change their color.
Could you please explain your situation? Or even better, could you please arrange a simple example project we can run as-is to reproduce the situation here?
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

JAV
Newbie
Newbie
Posts: 65
Joined: Thu May 12, 2011 12:00 am

Re: Customizing series on legend

Post by JAV » Mon Aug 22, 2011 10:05 pm

Thanks a lot for your time. It has been a great help and have solved the problems :D

Best regards,

JAV

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

Re: Customizing series on legend

Post by Yeray » Tue Aug 23, 2011 1:20 pm

Hi JAV,

You're welcome. I'm glad to hear that :D
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