Answered Charting on WinForm

PeterWJohnson

New member
Joined
Jul 21, 2014
Messages
3
Programming Experience
10+
Hi Guys,

I am trying to display a stripline on a chart that shows a particular date.

I have tried a number of different ways of coding.

' This works....
        Dim StartYear As Integer = 2014
        Dim StartMonth As Integer = 4
        Dim StartDay As Integer = 25
        Dim StartDate As Date = New Date(StartYear, StartMonth, StartDay)
 
        Dim sl1 As New StripLine
        sl1.Interval = 0
        sl1.IntervalOffset = (StartDate.ToOADate) - 0.25
        sl1.IntervalOffsetType = DateTimeIntervalType.Days
        sl1.StripWidth = StartDate.AddDays(0.5).ToOADate - StartDate.ToOADate
        sl1.StripWidthType = DateTimeIntervalType.Days
        sl1.BackColor = Color.Red
        sl1.Text = StartDay & "/" & StartMonth & "/" & StartYear
        Chart.ChartAreas(0).AxisX.StripLines.Add(sl1)
 


' But this doesn't....
        Dim StartYear As Integer = CType(cboPlannedStartYear.Text, Integer)
        Dim StartMonth As Integer = CType(cboPlannedStartMonth.Text, Integer)
        Dim StartDay As Integer = CType(cboPlannedStartDay.Text, Integer)
        Dim StartDate As Date = New Date(StartYear, StartMonth, StartDay)
 
        Dim sl1 As New StripLine
        sl1.Interval = 0
        sl1.IntervalOffset = (StartDate.ToOADate) - 0.25
        sl1.IntervalOffsetType = DateTimeIntervalType.Days
        sl1.StripWidth = StartDate.AddDays(0.5).ToOADate - StartDate.ToOADate
        sl1.StripWidthType = DateTimeIntervalType.Days
        sl1.BackColor = Color.Red
        sl1.Text = StartDay & "/" & StartMonth & "/" & StartYear
        Chart.ChartAreas(0).AxisX.StripLines.Add(sl1)
 

How can I use the variables StartYear, StartMonth and StartDay to give me a StartDate?

The piece of code that doesn't work displays nothing on the chart. I need the code that does work to display the line on the chart at the date passed by the variables.

Any ideas?

Cheers

Peter
 
Last edited by a moderator:
Thread moved from Web Forms to Windows Forms.

Unless I'm missing something, the only part that's different is the first three lines. In that case, obviously one of the first three lines is failing, presumably because at least one of the ComboBoxes doesn't contain a number when the code is executed. Have you checked that?
 
Thread moved from Web Forms to Windows Forms.

Unless I'm missing something, the only part that's different is the first three lines. In that case, obviously one of the first three lines is failing, presumably because at least one of the ComboBoxes doesn't contain a number when the code is executed. Have you checked that?


Thanks,

I added
VB.NET:
MsgBox(CType(cboPlannedStartDay.Text, Integer) & "/" & CType(cboPlannedStartMonth.Text, Integer) & "/" & CType(cboPlannedStartYear.Text, Integer))
and it displays the date correctly.
 
Place a break point (F9) on the first line of the code block and step through it line by line (F10) and see if it makes it all the way through. If not then an exception is being thrown so you can find out what went wrong from the exception.
 
Place a break point (F9) on the first line of the code block and step through it line by line (F10) and see if it makes it all the way through. If not then an exception is being thrown so you can find out what went wrong from the exception.

Thanks for that. I managed to get things working OK. More a problem with the dates along the Y axis than with the stripline.

Many thanks for your help.

Peter
 
Back
Top