Click here to Skip to main content
15,886,781 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i need a help in vb.net how to insert axis values in control chart using vb.net i wrote the coding to this but it not work in properly pls help it's my future...


VB
Imports System.IO
Imports System.Data.SqlClient
Imports System.Windows.Forms.DataVisualization.Charting

Public Class Form1
    Dim con As New SqlConnection
    Dim str As String
    Dim rsTemp As DataTable
    Dim a(1), ln As Integer
    Dim qury As New SqlCommand
    Dim sqldr As New SqlDataAdapter



    Private Sub btnshow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnshow.Click
        
        str = "Data Source=PROJECT\SQLEXPRESS;Initial Catalog=tt;User ID=base;Password=base"
        con = New SqlConnection(str)
        con.Open()
        qury = New SqlCommand("Delete from Time_1", con)

        qury.ExecuteNonQuery()
        con.Close()
        Dim da As New SqlDataAdapter
        Dim cb As New SqlCommandBuilder
        Dim dttemp As DataTable
        dttemp = New DataTable
        da = New SqlDataAdapter("select * from Time_2  where  month(TimeStamp)=" & Month(dtpfrom.Value) & " and year(TimeStamp)=" & Year(dtpfrom.Value) & " group by TimeStamp,Tagref,value order by TimeStamp", str)
        cb = New SqlCommandBuilder(da)
        da.Fill(dttemp)

        Dim c As Integer
        c = dttemp.Rows.Count


        Dim vUCL(c), vLCL(c), v6s(c), v3s(c), v6s1(c), v3s1(c), vCL(c) As Object
        Dim x, x1 As Double
        Dim Arr(c) As Single
        Dim avg, avg1 As Double

        Dim Average(c) As Single
        Dim Std_Dev(c) As Single
        Dim i As Long
        i = 1

        For Each row As DataRow In dttemp.Rows
            Arr(i) = row.Item(2)

            i = i + 1
        Next

        For Each row As DataRow In dttemp.Rows
            avg = avg + row.Item(2)
        Next
        avg1 = avg / c
      

        For i = 1 To c
            Average(i) = Mean(i, Arr)
            Std_Dev(i) = StdDev(i, Arr)
            x = 3 * Std_Dev(i)
            x1 = 6 * Std_Dev(i)

            con = New SqlConnection(str)
            con.Open()
            qury = New SqlCommand("insert into time_1 values('" & dttemp(i - 1).Item(0) & "','" & Arr(i) & "','" & x1 & "','" & x & "','" & avg1 & "','" & (-x) & "','" & (-x1) & "')", con)

            qury.ExecuteNonQuery()
            con.Close()


        Next
        Dim da1 As New SqlDataAdapter
        Dim cb1 As New SqlCommandBuilder
        Dim dttemp1 As DataTable
        dttemp1 = New DataTable

               da1 = New SqlDataAdapter("SELECT convert(varchar,TTime,108) as TTime, Temperature,  CL FROM dbo.Time_1", str)
        cb1 = New SqlCommandBuilder(da1)
        da1.Fill(dttemp1)
          MSChart1.DataSource = dttemp1
        MSChart1.Series(0).XValueMember = "TTime" 'values for X axis 
        MSChart1.Series(0).YValueMembers = "Temperature"
        MSChart1.Series(1).XValueMember = "TTime"
        MSChart1.Series(1).YValueMembers = "Temperature"
                MSChart1.DataBind()
        Dim dblMean As Double = MSChart1.DataManipulator.Statistics.Mean("Temp") 'uses datamanipulator to return mean

               Dim lstDates As New List(Of Date)
        Dim lstValues As New List(Of Double)
        Dim intTotalUnitsSold As Integer = 0
        For i1 As Integer = 0 To dttemp1.Rows.Count - 1
            intTotalUnitsSold += dttemp1.Rows(i1).Item(1)
            lstDates.Add(dttemp1.Rows(i1).Item(0))
            lstValues.Add(dttemp1.Rows(i1).Item(1))
                    Next
        MSChart1.Series(0).Points.DataBindXY(lstDates.ToArray, lstValues.ToArray)

        Dim dblMean1 As Double = MSChart1.DataManipulator.Statistics.Mean("CL") 'uses datamanipulator to return mean
                Dim lstDates1 As New List(Of Date)
        Dim lstValues1 As New List(Of Double)
        Dim intTotalUnitsSold1 As Integer = 0
        For i1 As Integer = 0 To dttemp1.Rows.Count - 1
            intTotalUnitsSold1 += dttemp1.Rows(i1).Item(2)
            lstDates1.Add(dttemp1.Rows(i1).Item(0))
            lstValues1.Add(dttemp1.Rows(i1).Item(2))

        Next
        MSChart1.Series(1).Points.DataBindXY(lstDates1.ToArray, lstValues1.ToArray)
End sub

Function Mean(ByVal k As Long, ByVal Arr() As Single)
       Dim Sum As Single
       Dim i As Integer

       Sum = 0
       For i = 1 To k
           Sum = Sum + Arr(i)
       Next i

       Mean = Sum / k

   End Function

   Function StdDev(ByVal k As Long, ByVal Arr() As Single)
       Dim i As Integer
       Dim avg As Single, SumSq As Single

       avg = Mean(k, Arr)
       For i = 1 To k
           SumSq = SumSq + (Arr(i) - avg) ^ 2
       Next i
       If k > 1 Then
           StdDev = Math.Sqrt(SumSq / (k - 1))
       End If
       'Return StdDev
   End Function

End class
Posted
Updated 18-Jan-12 23:40pm
v2
Comments
Sergey Alexandrovich Kryukov 19-Jan-12 4:21am    
WinForms? Add the tag! Also, format all the code fragments (not just one) with <pre lang="VB.NET">...</pre>. Use "Improve question" and explain the problem properly, otherwise your chanced to get any useful advice are very low.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900