Page 1 of 1

How to add a highlow series???

Posted: Mon Jul 24, 2006 5:08 pm
by 8120717
I am trying to produce a chart of two x-y linear series with the area between the lines filled in with color. If the first line y value is greater than the second line yValue a different color would be used (or different transparency - some way to indicate an "above the line" situation).

So while the first series is below the second, the area between the two series would be green... while the first series is above the second, red would be the color used to indicate the difference between the lines.

I think I need to use the HighLow series but I have no idea how to make this happen via code. Here's the code I am using to init the series:

Code: Select all

    Private Sub InitSeries(ByRef chrt As Steema.TeeChart.TChart, ByVal strName As String, ByVal clr1 As System.Drawing.Color, ByVal clr2 As System.Drawing.Color)

        Dim hl As New Steema.TeeChart.Styles.HighLow(chrt.Chart)
        hl.Color = clr1
        hl.Title = strName
        hl.XValues.DateTime = True
        hl.Pen.Visible = True
        hl.HighBrush.Visible = True
        hl.HighBrush.Color = clr1
        hl.HighBrush.Transparency = 65
        hl.HighBrush.Solid = True
        hl.LowBrush.Visible = True
        hl.LowBrush.Color = clr2
        hl.LowBrush.Transparency = 65
        hl.LowBrush.Solid = True

    End Sub
Here's what I am trying to use to get the values in but it does not pass the precompiler:

Code: Select all

    Private Sub AddChartVal(ByRef chrt As Steema.TeeChart.TChart, ByVal iSer As Integer, ByVal XVal As Date, ByVal LoVal As Double, ByVal HiVal As Double, ByVal strText As String)

        chrt.Series(iSer).Add(XVal, LoVal, HiVal, strText)

    End Sub
So there are two issues: how to set up the chart to produce the expected visual; and how to get values into the series via code.

How do I accomplish this? Or,,, is it even possible???

Posted: Wed Jul 26, 2006 9:00 am
by narcis
Hi Michael,

Yes, this is possible doing something like this:

Code: Select all

    Private Sub InitSeries(ByRef chrt As Steema.TeeChart.TChart, ByVal strName As String, ByVal clr1 As System.Drawing.Color, ByVal clr2 As System.Drawing.Color)

        Dim hl As New Steema.TeeChart.Styles.HighLow(chrt.Chart)
        hl.Color = clr1
        hl.Title = strName
        hl.XValues.DateTime = True
        hl.Pen.Visible = True

        hl.HighPen.Color = clr1
        hl.LowPen.Color = clr2

        hl.HighBrush.Visible = True
        hl.HighBrush.Color = clr1
        hl.HighBrush.Transparency = 65
        hl.HighBrush.Solid = True

        hl.LowBrush.Visible = True
        hl.LowBrush.Color = clr2
        hl.LowBrush.Transparency = 65
        hl.LowBrush.Solid = True

    End Sub

    Private Sub AddChartVal(ByRef chrt As Steema.TeeChart.TChart, ByVal iSer As Integer, ByVal XVal As Date, ByVal LoVal As Double, ByVal HiVal As Double, ByVal strText As String)
        CType(TChart1.Series(iSer), Steema.TeeChart.Styles.HighLow).Add(XVal.ToOADate(), LoVal, HiVal, strText)
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim h, l As New Double

        InitSeries(TChart1, "highLow1", Color.Red, Color.Blue)

        For i As Integer = 1 To 10
            h = (i - 1) * (i - 1)
            l = (i + 1) * 2

            AddChartVal(TChart1, 0, DateTime.Parse(i.ToString() + "/07/2006"), h, l, "Point " + i.ToString())
        Next

    End Sub

Posted: Wed Jul 26, 2006 2:16 pm
by 8120717
Exactly! This one sample has answered so many questions!!!

One type-o... For the benefit of the curious onlooker... the following:

Code: Select all

    Private Sub AddChartVal(ByRef chrt As Steema.TeeChart.TChart, ByVal iSer As Integer, ByVal XVal As Date, ByVal LoVal As Double, ByVal HiVal As Double, ByVal strText As String) 
        CType(TChart1.Series(iSer), Steema.TeeChart.Styles.HighLow).Add(XVal.ToOADate(), LoVal, HiVal, strText) 
    End Sub 
should be...

Code: Select all

    Private Sub AddChartVal(ByRef chrt As Steema.TeeChart.TChart, ByVal iSer As Integer, ByVal XVal As Date, ByVal LoVal As Double, ByVal HiVal As Double, ByVal strText As String) 
        CType(chrt.Series(iSer), Steema.TeeChart.Styles.HighLow).Add(XVal.ToOADate(), LoVal, HiVal, strText) 
    End Sub 
Thanks!
Excellent product and great support!

Posted: Wed Jul 26, 2006 2:38 pm
by narcis
Hi Michael,

Thanks, I'm glad to hear that fits your needs.
One type-o...
Yes, you are right. I missed the chart parameter. However, a simpler syntax is:

Code: Select all

    Private Sub AddChartVal(ByRef chrt As Steema.TeeChart.TChart, ByVal iSer As Integer, ByVal XVal As Date, ByVal LoVal As Double, ByVal HiVal As Double, ByVal strText As String)
        CType(chrt(iSer), Steema.TeeChart.Styles.HighLow).Add(XVal.ToOADate(), LoVal, HiVal, strText)
    End Sub