62,243
社区成员




while (this.Chart1.Series[0].Points.Count > 20)
{
foreach (Series s in this.Chart1.Series)
{
s.Points.RemoveAt(0);
}
}
double axisMinimum = this.Chart1.Series[0].Points[0].XValue;
this.Chart1.ChartAreas[0].AxisX.Minimum = axisMinimum;
this.Chart1.ChartAreas[0].AxisX.Maximum = axisMinimum + 20;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string strWhere = "";
DataTable myDataTable0 = tools.GetPageInfoTable("wxdysjjc", "bh,cgqmc,sbbh", "id", "0", strWhere, 0);
if (myDataTable0.Rows.Count > 0)
{
this.Chart1.Series[0].Points.AddXY(0, 0);
foreach (DataRow row in myDataTable0.Rows)
{
string seriesName = row["cgqmc"].ToString();
Chart1.Series.Add(seriesName);
Chart1.Series[seriesName].ChartType = SeriesChartType.Line;
Chart1.Series[seriesName].BorderWidth = 1;
this.Chart1.Series[seriesName].Points.AddXY(0, 0);
sbbhlist += row["sbbh"].ToString() + ",";
}
this.shebei_bh.Value = sbbhlist;
}
}
// Chart1.Titles.Add("数据监测");
Chart1.ChartAreas[0].AxisY.Title = "数值";
this.Chart1.Series[0].IsVisibleInLegend = true;
this.Chart1.ChartAreas[0].AxisX.Interval = 2;//数据间隔
this.Chart1.ChartAreas[0].AxisX.MinorTickMark.Interval = 2;//刻度
this.Chart1.ChartAreas[0].AxisX.MinorTickMark.Enabled = true;//显示刻度
}
protected void timer1_Tick(object sender, EventArgs e)
{
string allbh = this.shebei_bh.Value;
string strTmp = allbh.Substring(0, allbh.Length - 1);
if (strTmp != "")
{
string[] sbbhlist = strTmp.Split(',');
for (int i = 0; i < sbbhlist.Length; i++)
{
Series series = this.Chart1.Series[i];
int xCount = series.Points.Count == 0 ? 0 : series.Points.Count - 1;
// double lastXValue = series.Points.Count == 0 ? 1 : series.Points[xCount].XValue + 1;
double lastYValue = series.Points[series.Points.Count - 1].YValues[0];
double lastXValue = series.Points[series.Points.Count - 1].XValue + 1;
string strwhere = tools.GetWherePrameter("sbbh", "sbbh", sbbhlist[i].ToString(), DbOperator.Equal);
DataTable DataTablejilu = tools.GetPageInfoTable("wxdylsjl", "*", "cj_sj", "1", strwhere, 1);
if (DataTablejilu.Rows[0]["zhi"].ToString() != "")
{
lastYValue = Convert.ToInt32(DataTablejilu.Rows[0]["zhi"].ToString());
}
else
{
lastYValue = 0;
}
lastYValue = Convert.ToInt32(DataTablejilu.Rows[0]["zhi"].ToString());
series.Points.AddXY(lastXValue++, lastYValue);
while (this.Chart1.Series[0].Points.Count > 20)
{
foreach (Series s in this.Chart1.Series)
{
s.Points.RemoveAt(0);
}
}
double axisMinimum = this.Chart1.Series[0].Points[0].XValue;
this.Chart1.ChartAreas[0].AxisX.Minimum = axisMinimum;
this.Chart1.ChartAreas[0].AxisX.Maximum = axisMinimum + 20;
}
}
}
<form id="form1" runat="server">
<asp:HiddenField ID="shebei_bh" runat="server" />
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<asp:UpdatePanel ID="updatepanel1" runat="server">
<ContentTemplate>
<asp:Chart ID="Chart1" runat="server" BackColor="LightSteelBlue" BackGradientStyle="TopBottom"
BackSecondaryColor="White" EnableTheming="False" EnableViewState="True" Height="317px"
Width="415px">
<%-- <Legends>
<asp:Legend Alignment="Center" Docking="Bottom" Name="Legend1" Title="图例">
</asp:Legend>
</Legends>--%>
<Series>
<asp:Series Name="Series1" ChartType="Line">
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="Default" BorderColor="64, 64, 64, 64" BorderDashStyle="Solid"
BackSecondaryColor="White" BackColor="64, 165, 191, 228" ShadowColor="Transparent"
BackGradientStyle="TopBottom">
<Position Y="2" Height="94" Width="94" X="2"></Position>
<AxisY LineColor="64, 64, 64, 64" Maximum="100">
<LabelStyle Font="Trebuchet MS, 8.25pt, style=Bold"></LabelStyle>
<MajorGrid LineColor="64, 64, 64, 64"></MajorGrid>
</AxisY>
<AxisX LineColor="64, 64, 64, 64" IsMarginVisible="False" Maximum="20" Minimum="0"
IsStartedFromZero="False">
<LabelStyle Font="Trebuchet MS, 8.25pt, style=Bold"></LabelStyle>
<MajorGrid LineColor="64, 64, 64, 64"></MajorGrid>
</AxisX>
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
<div>
<asp:Timer ID="timer1" Interval="2000" runat="server" OnTick="timer1_Tick">
</asp:Timer>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
int xCount = series.Points.Count == 0 ? 0 : series.Points.Count - 1;
// double lastXValue = series.Points.Count == 0 ? 1 : series.Points[xCount].XValue + 1;
double lastYValue = series.Points[series.Points.Count - 1].YValues[0];
double lastXValue = series.Points[series.Points.Count - 1].XValue + 1;
protected void Page_Load(object sender, EventArgs e)
{
string myconn = ConfigurationManager.AppSettings["conn_access"];
OleDbConnection conn = new OleDbConnection(myconn);
string mysql = "select * from jcsj";
OleDbCommand cmd = new OleDbCommand(mysql, conn);
conn.Open();
OleDbDataAdapter oda = new OleDbDataAdapter();
oda.SelectCommand = cmd;
DataSet ds = new DataSet();
oda.Fill(ds);
sbCount = ds.Tables[0].Rows.Count;
if (!IsPostBack)
{
// Chart1.Titles.Add("数据监测");
this.Chart1.Series[0].Points.AddXY(0, 0);
foreach (DataRow row in ds.Tables[0].Rows)
{
string seriesName = row["cgqmc"].ToString();
Chart1.Series.Add(seriesName);
Chart1.Series[seriesName].ChartType = SeriesChartType.Line;
Chart1.Series[seriesName].BorderWidth = 1;
this.Chart1.Series[seriesName].Points.AddXY(0, 0);
}
}
Chart1.ChartAreas[0].AxisY.Title = "数值";
this.Chart1.ChartAreas[0].AxisX.Interval = 3;//数据间隔为5
this.Chart1.ChartAreas[0].AxisX.MinorTickMark.Interval = 3;//刻度为1
this.Chart1.ChartAreas[0].AxisX.MinorTickMark.Enabled = true;//显示刻度
}
protected void timer1_Tick(object sender, EventArgs e)
{
Random rand = new Random();
//for (int col = 1; col < ds.Tables[0].Columns.Count; col++)
//{
// string colName = ds.Tables[0].Columns[col].ColumnName;
// int yVal = Convert.ToInt32(row[colName].ToString());
// Chart1.Series[seriesName].Points.AddXY(colName, yVal);
//}
foreach (Series series in this.Chart1.Series)
{
double lastYValue = series.Points[series.Points.Count - 1].YValues[0];
double lastXValue = series.Points[series.Points.Count - 1].XValue + 1;
for (int pointIndex = 0; pointIndex < 5; pointIndex++)
{
lastYValue += rand.Next(-3, 4);
if (lastYValue >= 100.0)
{
lastYValue -= 25.0;
}
else if (lastYValue <= 10.0)
{
lastYValue += 25.0;
}
series.Points.AddXY(lastXValue++, lastYValue);
series.IsVisibleInLegend = true;
}
while (this.Chart1.Series[0].Points.Count > 60)
{
foreach (Series s in this.Chart1.Series)
{
s.Points.RemoveAt(0);
}
}
double axisMinimum = this.Chart1.Series[0].Points[0].XValue;
this.Chart1.ChartAreas[0].AxisX.Minimum = axisMinimum;
this.Chart1.ChartAreas[0].AxisX.Maximum = axisMinimum + 60;
}
}