首页 新闻 会员 周边 捐助

数据图形表示

0
[已解决问题] 解决于 2011-07-14 11:35

你从数据库查询出来,然后用图形的形式来表示数据,有人弄过吗。有代码提供吗

rains的主页 rains | 小虾三级 | 园豆:860
提问于:2010-08-19 14:35
< >
分享
最佳答案
0

WinForm 下面用 System.Windows.Forms.DataVisualization.Charting.Chart:

代码:

  public Form1()
        {
            InitializeComponent();

            var serieItem = this.chart1.Series[0];

            serieItem.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.RangeBar;
            serieItem.XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Time;
            serieItem.IsValueShownAsLabel = true;
            serieItem.IsXValueIndexed = true;
            serieItem.LabelAngle = 10;

            DataTable table = GetDataSource();
            DataPoint pointItem = null;
            for (int i = 0; i < table.Rows.Count; i++)
            {
                pointItem = new DataPoint();
                pointItem.SetValueXY(table.Rows[i]["TimeValue"], table.Rows[i]["Value"]);
                pointItem.AxisLabel = table.Rows[i]["Value"].ToString();
                serieItem.Points.Add(pointItem);
            }
        }

        DataTable GetDataSource()
        {
            DataTable table = new DataTable();
            table.Columns.Add("Value"typeof(double));
            table.Columns.Add("TimeValue"typeof(DateTime));

            DataRow row = table.NewRow();

            row["Value"] = 45;
            row["TimeValue"] = DateTime.Parse("2010-08-08 9:30");
            table.Rows.Add(row);

            row = table.NewRow();
            row["Value"] = 50;
            row["TimeValue"] = DateTime.Parse("2010-08-08 10:00");
            table.Rows.Add(row);

            row = table.NewRow();
            row["Value"] = 55;
            row["TimeValue"] = DateTime.Parse("2010-08-08 10:30");
            table.Rows.Add(row);

            row = table.NewRow();
            row["Value"] = 45;
            row["TimeValue"] = DateTime.Parse("2010-08-08 11:00");
            table.Rows.Add(row);

            row = table.NewRow();
            row["Value"] = 52;
            row["TimeValue"] = DateTime.Parse("2010-08-08 11:30");
            table.Rows.Add(row);

            row = table.NewRow();
            row["Value"] = 43;
            row["TimeValue"] = DateTime.Parse("2010-08-08 12:00");
            table.Rows.Add(row);

            row = table.NewRow();
            row["Value"] = 60;
            row["TimeValue"] = DateTime.Parse("2010-08-08 12:30");
            table.Rows.Add(row);

            return table;
        }

WebForm 下面用 System.Web.UI.DataVisualization.Charting.Chart:

代码:

 protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                var serieItem = this.Chart1.Series[0];

                serieItem.ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.RangeBar;
                serieItem.XValueType = System.Web.UI.DataVisualization.Charting.ChartValueType.Time;
                serieItem.IsValueShownAsLabel = true;
                serieItem.IsXValueIndexed = true;
                serieItem.LabelAngle = 10;

                DataTable table = GetDataSource();
                DataPoint pointItem = null;
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    pointItem = new DataPoint();
                    pointItem.SetValueXY(table.Rows[i]["TimeValue"], table.Rows[i]["Value"]);
                    pointItem.AxisLabel = table.Rows[i]["Value"].ToString();
                    serieItem.Points.Add(pointItem);
                }
            }
        }

        DataTable GetDataSource()
        {
            DataTable table = new DataTable();
            table.Columns.Add("Value"typeof(double));
            table.Columns.Add("TimeValue"typeof(DateTime));

            DataRow row = table.NewRow();

            row["Value"] = 45;
            row["TimeValue"] = DateTime.Parse("2010-08-08 9:30");
            table.Rows.Add(row);

            row = table.NewRow();
            row["Value"] = 50;
            row["TimeValue"] = DateTime.Parse("2010-08-08 10:00");
            table.Rows.Add(row);

            row = table.NewRow();
            row["Value"] = 55;
            row["TimeValue"] = DateTime.Parse("2010-08-08 10:30");
            table.Rows.Add(row);

            row = table.NewRow();
            row["Value"] = 45;
            row["TimeValue"] = DateTime.Parse("2010-08-08 11:00");
            table.Rows.Add(row);

            row = table.NewRow();
            row["Value"] = 52;
            row["TimeValue"] = DateTime.Parse("2010-08-08 11:30");
            table.Rows.Add(row);

            row = table.NewRow();
            row["Value"] = 43;
            row["TimeValue"] = DateTime.Parse("2010-08-08 12:00");
            table.Rows.Add(row);

            row = table.NewRow();
            row["Value"] = 60;
            row["TimeValue"] = DateTime.Parse("2010-08-08 12:30");
            table.Rows.Add(row);

            return table;
        }

可以看出两种控件的代码没大区别、就命名空间不同。
HUHU慈悲 | 大侠五级 |园豆:9973 | 2010-08-19 15:08
其他回答(2)
0

什么图形,可以用控件,或者自己根据数据画图输出。

Astar | 园豆:40805 (高人七级) | 2010-08-19 14:39
0

请问这个东西是不是要装了vs2008 sp1版才能用啊,我要装sp1时需要C盘 空间5G多,而我空间不够 ,只有3G多,现在只装了vs2008,怎么办,我需要这个功能

C云 | 园豆:125 (初学一级) | 2010-12-07 15:52
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册