我目前使用asp:图表控件生成图表
该图表是一个真实的实时图表,每秒不断更新
这是我项目的前端代码
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick"></asp:Timer>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="tick" />
</Triggers>
<ContentTemplate>
<div style="height:70%">
<asp:Chart ID="chart" runat="server" Width="1700px" Height="600px">
<Titles>
<asp:Title Text="Chart" Font="Times New Roman, 24pt, style=Bold" ForeColor="White" />
</Titles>
<Series>
<asp:Series ChartType="Area" Name="Level" XValueMember="Time" YValueMembers="Level" IsVisibleInLegend="true" IsValueShownAsLabel="true" YValuesPerPoint="2" Color="90, 39, 174, 96">
</asp:Series>
<asp:Series ChartType="Area" Name="Percentage" XValueMember="Time" YValueMembers="Percentage" IsVisibleInLegend="true" IsValueShownAsLabel="true" YValuesPerPoint="2" Color="90, 155, 89, 182">
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="ChartArea1" BackColor="White">
<AxisX LineColor="Gray" Interval = "1" Title="Time(hh:mm:ss)" TitleForeColor="White">
<MajorGrid LineColor="Gray" />
<LabelStyle ForeColor="white" />
</AxisX>
<AxisY LineColor="Gray" Interval = "5" Title="Levek/Percentage" TitleForeColor="White">
<MajorGrid LineColor="Gray" />
<LabelStyle ForeColor="white" />
</AxisY>
<Area3DStyle Enable3D="true" LightStyle="Realistic"></Area3DStyle>
</asp:ChartArea>
</ChartAreas>
<Legends>
<asp:Legend BackColor="Transparent" ForeColor="white">
</asp:Legend>
</Legends>
</asp:Chart>
</div>
</ContentTemplate>
</asp:UpdatePanel>
这是我项目的后端代码
Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles Timer1.Tick
Dim dtTable As New Data.DataTable
Dim strSQL As String = "SELECT level, percentage, time FROM Record ORDER BY date DESC, time DESC"
If Not db_connSQL(strSQL, dtTable) Then
Exit Sub
End If
If dtTable.Rows.Count > 0 Then
chart.DataSource = dtTable
chart.DataBind()
End If
End Sub
我喜欢使用UpdatePanel和AsyncPostBackTrigger。
但图表仍然闪烁。
任何人都可以帮助我吗?