使用WebChart怎么绘制按小时统计,按天统计,按月统计的流量图?(要实时更新的)
有哪位用过WebChart控件绘制流量统计图形吗?给点代码研究一下啊。网上搜了一圈,搞了好长时间就是做不出好的效果来。这个控件还是蛮好用的,画出来的图形也很漂亮.只是本人才刚接触统计图形,不知道怎么弄,做过统计图形方面的兄弟们指点下小弟啊!!!WebChart控件:
WebChart.rar
(36.62 KB)
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
using System.Data.SqlClient;
using System.Drawing.Drawing2D;
using WebChart;
public partial class Default4 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
CreateChart();
}
public void CreateChart()
{
DataSet ds = CreateDataSet();
ColumnChart chart = new ColumnChart();
chart.MaxColumnWidth = 10;
chart.Fill.Color = Color.FromArgb(50, Color.Red);
chart.Shadow.Visible = true;
chart.Legend = "Pri 0";
ColumnChart chart1 = new ColumnChart();
chart1.MaxColumnWidth = 10;
chart1.Fill.Color = Color.FromArgb(50, Color.Yellow);
chart1.Shadow.Visible = true;
chart1.Legend = "Pri 1";
LineChart chart5 = new LineChart();
chart5.Line.Color = Color.Green;
chart5.Fill.Color = Color.Green;
chart5.LineMarker = new DiamondLineMarker(8, Color.Green, Color.Yellow);
chart5.Legend = "Goal";
foreach (DataRow row in ds.Tables[0].Rows)
{
chart.Data.Add(new ChartPoint(row["date"].ToString(), (int)row["pri0"]));
chart1.Data.Add(new ChartPoint(row["date"].ToString(), (int)row["pri1"]));
chart5.Data.Add(new ChartPoint(row["date"].ToString(), (int)row["goal"]));
}
ChartControl1.Charts.Add(chart);
ChartControl1.Charts.Add(chart1);
ChartControl1.Charts.Add(chart5);
ChartControl1.RedrawChart();
}
/// <summary>
/// Just generate some random data
/// </summary>
DataSet CreateDataSet()
{
DataSet ds = new DataSet();
DataTable table = ds.Tables.Add("Table");
table.Columns.Add("date");
table.Columns.Add("pri0", typeof(int));
table.Columns.Add("pri1", typeof(int));
table.Columns.Add("pri2", typeof(int));
table.Columns.Add("pri3", typeof(int));
table.Columns.Add("total", typeof(int));
table.Columns.Add("goal", typeof(int));
Random rnd = new Random();
for (int i = 0; i < 15; i++)
{
DataRow row = table.NewRow();
row["date"] = DateTime.Now.AddDays(i).ToString("yy/dd");
int pri0 = rnd.Next(200);
int pri1 = rnd.Next(200);
int pri2 = rnd.Next(200);
int pri3 = rnd.Next(200);
int sum = pri0 + pri1 + pri2 + pri3;
int goal = rnd.Next(sum);
row["pri0"] = pri0;
row["pri1"] = pri1;
row["pri2"] = pri2;
row["pri3"] = pri3;
row["total"] = sum;
row["goal"] = goal;
table.Rows.Add(row);
}
return ds;
}
}
以上代码是我从网上找的,给大家参考一下。再给个外国的网站,在做统计图形方面的兄弟们如果有兴趣的话可以跟我一起研究一下:http://www.这个外国网站上有些例子和代码!!!
[[it] 本帖最后由 ruanjian2110 于 2008-6-9 17:30 编辑 [/it]]