Another problem with errorbar and negative values

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Oli
Newbie
Newbie
Posts: 42
Joined: Fri Jan 13, 2012 12:00 am

Another problem with errorbar and negative values

Post by Oli » Thu Apr 19, 2012 12:02 am

Hi,

as an additional post to the most recent one, I had also problems with errorbars and negative values.

I created the attached chart as boxplot (invisible box and whisker, visible mean line) and added errorbars. The series "A" was created with Errorbar.Add(0, -3, 5, "A"), and the other series "B" with Errorbar.Add(1, 3, 5, "B"). As it can be seen the errorbar "A" has only a distance of 2 to the mean value, whereas errorbar "B" has the correct distance of 5. In other words, I would expect the errorbar "A" to start at -8 and end at +2. I am using the latest version Teechart.Net 4.1.2012.02283.

Oli
Attachments
Errorbar_negValues.PNG
Errorbar_negValues.PNG (13.56 KiB) Viewed 3951 times

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Another problem with errorbar and negative values

Post by Sandra » Thu Apr 19, 2012 12:19 pm

Hello Oli,

Next code works fine for me, so the distance of Error1 and Error 2 are correct fore me:

Code: Select all

    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()
        InitializeChart()

        ' Add any initialization after the InitializeComponent() call.

    End Sub
    Private boxSeries1 As Steema.TeeChart.Styles.Box, boxSeries2 As Steema.TeeChart.Styles.Box
    ',boxSeries3;
    Private error1 As Steema.TeeChart.Styles.Error, error2 As Steema.TeeChart.Styles.Error
    Private Sub InitializeChart()
        tChart1.Aspect.View3D = False
        tChart1.Panel.MarginBottom = 10
        boxSeries1 = New Box(tChart1.Chart)
        boxSeries2 = New Box(tChart1.Chart)
        error1 = New [Error](tChart1.Chart)
        error2 = New [Error](tChart1.Chart)

        'BoxSeries1
        boxSeries1.Add(New Double(5) {-3, -6, -8, 15, 19, 21})
        boxSeries1.Position = 0
        CustomizeBoxSeries(boxSeries1)
        boxSeries1.Title = "A"
        boxSeries2.Add(New Double(3) {5, 7, 12, 21})
        boxSeries2.Position = 1
        CustomizeBoxSeries(boxSeries2)
        boxSeries2.Title = "B"

        '    //Error1

        error1.Add(boxSeries1.Position, CalculateMedian(boxSeries1), 5)
        error1.Add(boxSeries2.Position, CalculateMedian(boxSeries2), 5)
        error1.ErrorPen.Width = 2
        error1.Color = Color.Black
        error1.ErrorWidth = boxSeries1.Box.HorizSize / 2
        error1.ErrorStyle = ErrorStyles.Top
        error1.HorizAxis = HorizontalAxis.Top
        error1.MultiBar = MultiBars.None
        error1.ShowInLegend = False
        '    //Error2
        error2.Add(boxSeries1.Position, CalculateMedian(boxSeries1), 5)
        error2.Add(boxSeries2.Position, CalculateMedian(boxSeries2), 5)

        error2.ErrorPen.Width = 2
        error2.Color = Color.Black
        error2.ErrorWidth = boxSeries1.Box.HorizSize / 2
        error2.ErrorStyle = ErrorStyles.Bottom
        error2.HorizAxis = HorizontalAxis.Bottom
        error2.MultiBar = MultiBars.None
        error2.ShowInLegend = False

        '    //Axes
        TChart1.Axes.Top.Visible = False
        TChart1.Axes.Bottom.Labels.Items.Add(0, "A")
        TChart1.Axes.Bottom.Labels.Items.Add(1, "B")



    End Sub

    Private Function CalculateMedian(ByVal series As Box) As Double
        Dim median As Double
        median = 0.0
        Dim N As Integer = series.SampleValues.Count
        If N > 0 Then
            Dim InvN As Double = 1.0 / N
            ' calculate median 

            Dim med As Integer = N \ 2
            If (N Mod 2) = 0 Then
                median = 0.5 * (series.SampleValues(med - 1) + series.SampleValues(med))
            Else
                median = series.SampleValues(med)
            End If
        End If
        Return median
    End Function
    Private Sub CustomizeBoxSeries(ByVal boxSeries As Box)
        boxSeries.MedianPen.Color = Color.Black
        boxSeries.MedianPen.Width = 2
        boxSeries.MedianPen.Style = System.Drawing.Drawing2D.DashStyle.Solid
        boxSeries.WhiskerPen.Visible = False
        boxSeries.ExtrOut.Visible = False
        boxSeries.MildOut.Visible = False
        boxSeries.Box.HorizSize = 50
        boxSeries.Box.Visible = False
    End Sub
Can you tell as if previous code works fine for you?

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply