Page 1 of 1

Series draw order.

Posted: Wed Apr 28, 2010 1:03 pm
by 9530487
Hello all,

I have two series, a line and a highlow series to show some bounds.

I want the line series to appear on top of the highlow series, but I want the line series to appear first in the list of series in the editor.

Is there any way in code to make the highlow appear underneath the line series?

Thanks in advance,

Tony.

Re: Series draw order.

Posted: Thu Apr 29, 2010 10:23 am
by yeray
Hi Tony,

What you could do is to change the legend text and symbol as you want like in the demos at:
- What's new ?\Welcome !\New in Legend\Items property
- All Features\Welcome !\Miscellaneous\Legend\Symbol OnDraw

Or you could hide the two series from the legend (TChart1.Series(0).ShowInLegend = false) and create two dummy series (series without data) in the order you wish to show them as if they were the "original" series.

Re: Series draw order.

Posted: Thu Apr 29, 2010 4:48 pm
by 9530487
I've tried changing the drawing order, but as I'm using OnLegendGetText to change the legend entry, things are getting difficult. Hiding series causes all sorts of problems (OnLegendGetText is still called, but if you have hidden series, there is no easy way of working out what series is generating the OnLegendGetText).

I'll continue and see if I can figure a way around the problems.

Tony.

Re: Series draw order.

Posted: Fri Apr 30, 2010 7:29 am
by yeray
Hi Tony,

Here is one of the proposed solutions:

Code: Select all

Private Sub Form_Load()
  TChart1.AddSeries scArea
  TChart1.AddSeries scLine
    
  TChart1.Series(0).Title = "Area Series"
  TChart1.Series(1).Title = "Line Series"
  
  TChart1.Series(0).FillSampleValues 25
  TChart1.Series(1).FillSampleValues 25
End Sub

Private Sub TChart1_OnGetLegendText(ByVal LegendStyle As Long, ByVal ValueIndex As Long, LegendText As String)
  LegendText = TChart1.Series((ValueIndex + 1) Mod (TChart1.SeriesCount)).Title
End Sub

Private Sub TChart1_OnLegendDrawSymbol(ByVal Series As Long, ByVal ValueIndex As Long, ByVal Left As Long, ByVal Top As Long, ByVal Right As Long, ByVal Bottom As Long)
    With TChart1.Canvas
      If Series <> -1 Then
        .Brush.Color = TChart1.Series((Series + 1) Mod (TChart1.SeriesCount)).Color
        .Rectangle Left, Top, Right, Bottom
      End If
    End With
End Sub
And here the other:

Code: Select all

Private Sub Form_Load()
  TChart1.AddSeries scArea
  TChart1.AddSeries scLine
    
  TChart1.Series(0).Title = "Area Series"
  TChart1.Series(1).Title = "Line Series"
  
  TChart1.Series(0).FillSampleValues 25
  TChart1.Series(1).FillSampleValues 25
  
  TChart1.Series(0).ShowInLegend = False
  TChart1.Series(1).ShowInLegend = False
  
  TChart1.AddSeries scLine
  TChart1.AddSeries scLine
    
  TChart1.Series(2).Title = TChart1.Series(1).Title
  TChart1.Series(3).Title = TChart1.Series(0).Title
  
  TChart1.Series(2).Color = TChart1.Series(1).Color
  TChart1.Series(3).Color = TChart1.Series(0).Color
End Sub

Re: Series draw order.

Posted: Fri Apr 30, 2010 3:09 pm
by 9530487
Things are getting into a right mess when I hide legend entries. On removing a series that had it's legend entry hidden, the legend entry comes back (even though there is no series).

Unfortunately the solutions you propose will only work in very simple graphs. I have a mixture where some plots have "bounds" (hence the use of the hilow series), others will not have bounds displayed.

Re: Series draw order.

Posted: Fri Apr 30, 2010 3:42 pm
by yeray
Hi Tony,

Please, send us a simple example project we can run as-is here to reproduce your problem. I understand that your chart needs some features that may conflict with the proposed solutions, but, if we understand what are you exactly doing (or allowing the users to do) we may think on another solution or a variation of the above.

Re: Series draw order.

Posted: Fri Apr 30, 2010 4:39 pm
by 9530487
I've attached a project.

Click "Command2" followed by "Command3".

Re: Series draw order.

Posted: Mon May 03, 2010 9:00 am
by yeray
Hi Tony,

And could you explain how would you expect the application sent to respond?

I can see a known problem with it, related with RemoveSeries method:
http://www.teechart.net/support/viewtop ... 53&start=0

Simplifying your application a little bit, here is what I have:

Code: Select all

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

  TChart1.AddSeries scHighLow
  TChart1.AddSeries scLine
   
  TChart1.Series(0).Title = "HiLo Series"
  TChart1.Series(1).Title = "Line Series"
      
  TChart1.Series(0).Color = RGB(255, 0, 0)
  TChart1.Series(1).Color = RGB(255, 0, 0)
  
  For i = 0 To 100
      TChart1.Series(1).AddXY i, i, "", RGB(255, 0, 0)
      TChart1.Series(0).asHighLow.AddHighLow i, i * 1.2, i * 0.8, "", RGB(255, 0, 0)
  Next i
 
  TChart1.Series(0).asHighLow.Transparency = 60
  TChart1.Series(0).asHighLow.HighBrush.Style = bsSolid
  TChart1.Series(0).asHighLow.LowBrush.Style = bsSolid
  TChart1.Series(0).asHighLow.HighPen.Visible = True
  TChart1.Series(0).asHighLow.LowPen.Visible = True
  
  TChart1.Series(0).ShowInLegend = False
  TChart1.Series(0).ShowInEditor = False
  TChart1.Series(1).ShowInLegend = True
  
  TChart1.Legend.LegendStyle = lsSeries
End Sub

Private Sub TChart1_OnGetLegendText(ByVal LegendStyle As Long, ByVal ValueIndex As Long, LegendText As String)
    Select Case ValueIndex
    Case 0:
    LegendText = "My Series - Bounds"
    Case 1:
    LegendText = "My Series"
    End Select
End Sub

Private Sub Command1_Click()
  TChart1.Series(0).Active = False
End Sub
So, what would you expect to see when the button is pressed?

Re: Series draw order.

Posted: Mon May 03, 2010 4:42 pm
by 9530487
>> And could you explain how would you expect the application sent to respond?
Yes. Click command2 to give the plot and it's bounds. Click command3 to just show the plot, but the legend now has "My series - bounds", "My Series", plus values "2" - "24", only "My Series" should be shown. When I call "TChart1.Legend.LegendStyle = lsSeries" as your suggestion, that seems to remove the numerical values. But should I have to even call that as I didn't change the legend style in the first place?

>> I can see a known problem with it, related with RemoveSeries method:viewtopic.php?f=1&t=10953&start=0
ok.

Any idea when this fix will be available? And in the next update, can you add in the ability to have a legend entry different to series name without having to rely on OnLegendGetText (http://www.teechart.net/support/viewtop ... 2&start=15)? My code is increasingly becoming full of fixes and workarounds because of things like this.

Re: Series draw order.

Posted: Tue May 04, 2010 12:02 pm
by yeray
Hi Tony,
TonyVSUK wrote:Yes. Click command2 to give the plot and it's bounds. Click command3 to just show the plot, but the legend now has "My series - bounds", "My Series", plus values "2" - "24", only "My Series" should be shown. When I call "TChart1.Legend.LegendStyle = lsSeries" as your suggestion, that seems to remove the numerical values. But should I have to even call that as I didn't change the legend style in the first place?
By default LegendStyle is lsAuto. This style works as lsValues (lists all the values in the first visible series) when you have one series active and as lsSeries (lists all the series names) when you have more then one series active. So, when you click command2, you have one series (all its values are going to be shown in the legend) and you change the first two legend rows with the OnGetLegendText event. If you want to always have as many items in the legend as series active, you can force it with:

Code: Select all

TChart1.Legend.LegendStyle = lsSeries
TonyVSUK wrote:Any idea when this fix will be available? And in the next update, can you add in the ability to have a legend entry different to series name without having to rely on OnLegendGetText (viewtopic.php?f=1&t=10102&start=15)? My code is increasingly becoming full of fixes and workarounds because of things like this.
I'm afraid I can't tell you a date for this to be implemented. I recommend you to be aware at this forum or subscribe to our RSS news feed for new release announcements and what's implemented on them.

Re: Series draw order.

Posted: Tue May 04, 2010 12:20 pm
by 9530487
Yeray wrote:I'm afraid I can't tell you a date for this to be implemented. I recommend you to be aware at this forum or subscribe to our RSS news feed for new release announcements and what's implemented on them.
I regularly visit the website. But I've been struggling with OnLegendGetText for nearly a year now, no mention of it being added in the latest release even though you said it was on the list (http://www.teechart.net/support/viewtop ... 2&start=15).

Re: Series draw order.

Posted: Tue May 04, 2010 3:18 pm
by yeray
Hi Tony,

Regarding this, please see my reply on the according thread:
http://www.teechart.net/support/viewtop ... =15#p46627