Search code examples
vb.netzedgraph

zedgraph, how to convert XAxis.Scale.Min to a date


I use zedgraph to draw figures in my vb.net project. The x axis of figure is date. I have two text boxes showing the minimum and maximum values of x axis in date. The following code shows how to get x axis values when a figure is zoomed by using isEnableWheelZoom property, also see this link zedgraph EnableWheelZoom, how to get axis values after zooming?. But I found that I only get axis value, e.g. 4508.345, but NOT the date that I want. Actually on figure, it shows date correctly. My question is how to get the minimum and maximum date on figure?

    Friend WithEvents gcMain As ZedGraph.ZedGraphControl 
Me.gcMain.IsZoomOnMouseCenter = True 
Me.gcMain.IsEnableWheelZoom = True 

    Private Sub gcMain_ZoomEvent(ByVal sender As ZedGraphControl, ByVal oldState As ZoomState, ByVal newState As ZoomState) Handles gcMain.ZoomEvent
    tbxRangeStart.Text = CStr(New XDate(gcMain.GraphPane.XAxis.Scale.Min))
    tbxRangeEnd.Text = CStr(New XDate(gcMain.GraphPane.XAxis.Scale.Max))

End Sub

Solution

  • You almost got it. You only need to convert it to DateTime:

    Dim minDate As XDate = New XDate(gcMain.GraphPane.XAxis.Scale.Min)
    tbxRangeStart.Text = minDate.DateTime.ToString()
    

    See API for more information about the XData-Format.