Pages - Menu

2013年8月22日 星期四

MS Chart 使用兩條線做線圖...Multiple line

'假如是第二次載入
If Page.IsPostBack Then
Chart1.Visible = True
Dim date_s, date_e, type As String
Dim conn = New SqlConnection
Dim cmd As SqlCommand
Dim dr As SqlDataReader
Dim dt As DataTable = New DataTable
Dim SqlString As String
date_s = TextBox1.Text
date_e = TextBox2.Text
type = DropDownList1.SelectedValue
'date_s = "2013-08-21 16:48:00.000"
'date_e = "2013-08-21 17:50:00.000"
'type = "Co2"
conn.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString() '使用web config
SqlString = "select * from environment_log " & _
" where CONVERT (VARCHAR(10), timestamp, 111) >='" + date_s & _
"' and CONVERT (VARCHAR(10), timestamp, 111) <= '" + date_e & _
"' and type='" + type + "' order by timestamp"
'Label1.Text = SqlString
cmd = New SqlCommand(SqlString, conn) '定義cmnd為SqlCommand指令
'comnd.ExecuteNonQuery() '執行
Try
conn.Open() '開啟連結
dr = cmd.ExecuteReader() '讀取
If dr.HasRows = True Then
'第一種datareader 塞入datatable,使用多個線圖仍須測試
dt.Load(dr)
''Use linq to datatable
'Dim search1 = From c In dt.AsEnumerable() _
'Where c.Field(Of String)("DriverID") = "temp1" _
'Select c
'Dim temp1 = search1.CopyToDataTable()
'Dim search2 = From c In dt.AsEnumerable() _
'Where c.Field(Of String)("DriverID") = "temp2" _
'Select c
'Dim temp2 = search2.CopyToDataTable()
'Chart1.DataSource = temp2
'Chart1.Series("Series1").XValueMember = "timestamp"
'Chart1.Series("Series1").YValueMembers = "value"
''Chart1.Series("Series2").XValueMember = "timestamp"
''Chart1.Series("Series2").YValueMembers = "value"
'第二種使用databindcrosstable
'Use DataBindCrossTable
Chart1.DataBindCrossTable(dt.Rows, "DriverID", "timestamp", "value", "")
'不使用下列方式,只會跑長條圖..
For Each cs As Series In Chart1.Series
cs.ChartType = SeriesChartType.Spline
'cs.IsValueShownAsLabel = True
Next
Chart1.DataBind()
End If
Catch ex As Exception
Response.Write(e.ToString())
Finally
If Not (dr Is Nothing) Then ' --關閉 DataReader
cmd.Cancel() '--自己補上的,原因在下面有講。
dr.Close()
End If
If (conn.State = ConnectionState.Open) Then ' --關閉 DB的連線
conn.Close()
End If
End Try

End If

2013年8月18日 星期日

AJAX Toolkit問題彙整


1.無法修改 Controls 集合,因為控制項包含程式碼區塊 (例如 <% ... %>)。



因為有使用master,所以在head裡面找是不是有<%..%>的語法



結果真的有...<script type="text/javascript" src='<%= ResolveClientUrl("~/Scripts/master.js") %>'></script>


把這段移到body裡面就好了。


2.compile 的時候出現,找不到 ScriptObjectBuilder.cs



把這個加到aspx 內


<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>



3.ajax元件沒作用
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
改成

<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" > </ajaxToolkit:ToolkitScriptManager>