none
How to set a Chart control (line graph) to display floating point values? RRS feed

  • Question

  • Hi,

    I am trying to setup a Chart in Visual basic to display values. However, When I pass it single precision values it puts the point at the nearest integer. In other words I tell it to plot at value 2.4, and it puts the point at 2. How do you fix that? Thanks.

    Sunday, February 2, 2014 1:38 PM

Answers

  • Nevermind, It was in here:

    'Load the graph dtMain.Columns.Add("Time", GetType(Integer)) dtMain.Columns.Add("Speed", GetType(Integer))

    Shouldn't have been integer.Thanks.

    Sunday, February 2, 2014 7:25 PM

All replies

  • Lets see your code. And a pic of the chart maybe.
    Sunday, February 2, 2014 3:18 PM
  • Here is the code pertaining to the chart

        Public Sub LoadGraph()
    
            Try
    
                Dim intIndex, intLoc, intStart, intYMax, intXMax, intXInterval, intYInterval, intRows As Integer
                Dim strString As String
                Dim fltData(680) As Single
    
                dtMain.Columns.Clear()
                dtMain.Rows.Clear()
    
                'If a file is loaded
                If m_blnChipPresent = True And m_blnFileOpen = True Then
                    'If file has data
                    If m_clsFile.strFileData.Length > 1 Then
    
                        'Load the graph 
                        dtMain.Columns.Add("Time", GetType(Integer))
                        dtMain.Columns.Add("Speed", GetType(Integer))
    
                        strString = m_clsFile.strFileData
    
                        intStart = 0
                        intRows = 0
    
                        'Do until the string is empty
                        Do Until strString.Length = 0
                            'Get the location of delimiter
                            intLoc = strString.IndexOf("@")
    
    
                            'Get the data point
                            fltData(intRows) = Single.Parse(strString.Substring(0, intLoc))
    
                            'Remove substring to delimiter
                            strString = strString.Remove(0, intLoc + 1)
    
                            intRows += 1
    
                        Loop
    
                        'Set max speed to  0
                        intYMax = 0
    
                        'Add speeds to graph in 1 second intervals
                        For intIndex = 0 To fltData.Length - 1
                            'Add Data
                            dtMain.Rows.Add(intIndex, fltData(intIndex))
    
                            'If new max
                            If fltData(intIndex) > intYMax Then
                                'Set new max
                                intYMax = fltData(intIndex)
                            End If
                        Next
    
                        'Set offset to max speed 
                        intYMax *= 1.15
    
                        'Set offset for max time
                        intXMax = intRows * 1.15
    
                        intYInterval = intYMax / 20
    
                        intXInterval = intXMax / 20
    
    
                        'Setup Chart
                        With chtMain.ChartAreas(0)
                            .AxisX.Minimum = 0
                            .AxisX.Maximum = intXMax
                            .AxisX.Interval = intXInterval
                            .AxisY.Minimum = 0
                            .AxisY.Maximum = intYMax
                            .AxisY.Interval = intYInterval
                            .AxisX.Title = "Elapsed Time (s)"
                            .AxisY.Title = "Speed (knots)"
                        End With
    
                        'Setup chart series detail
                        With chtMain.Series(0)
    
                            .Points.DataBind(dtMain.DefaultView, "Time", "Speed", Nothing)
                            .ChartType = DataVisualization.Charting.SeriesChartType.Line
                            .BorderWidth = 4
                            .Name = "Speed"
                        End With
    
                    End If
    
                End If
    
            Catch ex As Exception
    
                SendError(ex.ToString())
    
            End Try
    
        End Sub
    And it will not let me show the picture because it says that it needs to verify my account??? I thought it already did that. but the problem is that with the Y axis Points of 0.00,1.24,16.98,13.45,2.10, and 0.00,  it appears like 0,1,17,13,2,0 in the graph. In other words it rounds them to the nearest integer.
    Sunday, February 2, 2014 5:23 PM
  • Nevermind, It was in here:

    'Load the graph dtMain.Columns.Add("Time", GetType(Integer)) dtMain.Columns.Add("Speed", GetType(Integer))

    Shouldn't have been integer.Thanks.

    Sunday, February 2, 2014 7:25 PM