2013-06-25 1 views
0

저는 데이터베이스로 vb.net과 sql을 사용하고 있습니다. 선 그래프를 플로팅하는 방법은 무엇입니까? 이 SQL 문을 사용하여vb.net에서 데이터베이스 (sql)의 값을 읽어서 선 그래프를 그리는 방법은 무엇입니까?

X 축은 내가 할당 한 사용자가 입력 한 Time_stamp의 범위 값이됩니다. = 6/24/2013 8:38:00 AM에서 6/24/오전 8시 38분 23초 2013 내 Y 축은 키에있는 것이다 사용자에 의해 BB_ID 될 것입니다 그리고 난 3100

= 같은이 내 일반 코드임을 지정 :

Dim connectionString As String = "server='abc'; user id='***'; password='***'; Database='***'" 
    Dim sqlConnection As SqlClient.SqlConnection = New SqlClient.SqlConnection(connectionString) 

    sqlConnection.Open() 

    Dim queryString As String = "SELECT Time_stamp, BB_ID, Status, " & _ 
    "(CASE WHEN Status = 'R' THEN 0 WHEN status = 'O' THEN 1 ELSE 2 END) AS newstatus"& _ 
    "FROM(dbo.rawdata)" & _ 
    "WHERE (BB_ID = '3100') AND (Time_stamp >= '6/24/2013 8:38:00 AM') AND (Time_stamp <= '6/24/2013 8:38:23 AM')" 

    Chart1.Series("line_area").Points.AddXY("3100", "10") 
    Chart1.Series("line_area").Points.AddXY("3100", "8") 
    Chart1.Series("line_area").ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Line 

    sqlConnection.Close() 

답변

0

필요가 없습니다 ZedGraph로 변경하십시오. MSChart는이 경우에도 잘 작동합니다. 쿼리 문자열을 만들었지 만 데이터베이스를 쿼리하지 않습니다. 코드

Chart1.Series("line_area").Points.AddXY("3100", "10") 
Chart1.Series("line_area").Points.AddXY("3100", "8") 

에서

string connectionString = // your connection string 
string queryString =  // your query string 

// Create a database connection object using the connection string  
SQLConnection sqlConnection = // your connection object 

// Create a database command on the connection using query  
SQLCommand sqlCommand = // your command 

sqlConnection .Open(); 

// set chart data source - the data source must implement IEnumerable 
chart1.DataSource = sqlCommand.ExecuteReader(CommandBehavior.CloseConnection); 

// Set series members names for the X and Y values 
chart1.Series["line_area"].XValueMember = "Time_stamp"; // the column you want on X axis 
chart1.Series["line_area"].YValueMembers = "BB_ID"; // the column you want on Y axis 

// Data bind to the selected data source 
chart1.DataBind(); 

당신은 차트에 두 점을 추가하는 모든 데이터베이스의 데이터가 모두 차트에 연결되어 있지 않습니다 이잖아.