2011. 1. 3. 23:20

New ASP.NET Charting Control

MS에서 제공하는 Chart 컨트롤입니다. 

Microsoft recently released a cool new ASP.NET server control - <asp:chart /> - that can be used for free with ASP.NET 3.5 to enable rich browser-based charting scenarios:





하기에는 실시간으로 차트를 업데이트하는 예제의 링크입니다.

protected void Timer1_Tick(object sender, EventArgs e)
{
   Series s = Chart1.Series["Series1"];
   //Determine the next X value
   double nextX = 1;

   if (s.Points.Count > 0)
   {
      nextX = s.Points[s.Points.Count-1].XValue+1;
   }

   //Add a new value to the Series
   Random rnd = new Random();
   s.Points.AddXY(nextX,(rnd.NextDouble() * 10)-5);

   //Remove Points on the left side after 100
   while (s.Points.Count > 100)
   {
      s.Points.RemoveAt(0);
   }

   //Set the Minimum and Maximum values for the X Axis on the Chart
   double min = s.Points[0].XValue;
   Chart1.ChartAreas[0].AxisX.Minimum = min;
   Chart1.ChartAreas[0].AxisX.Maximum = min + 100;
}