Chart控件的用法

时间:2020-11-28 07:26:51

最近用到统计方面的功能,文档统计不用说,都是导出Excel,若要视图效果,这里推荐一个Asp.NET中的控件Char。

Chart控件的用法

简单示例:

 

视图显示说明:

Chart控件的用法

可以设定Series的ChartType属性值,来决定显示什么样的视图,下面是常用的视图举例:

Chart控件的用法Chart控件的用法

后台绑定代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
protected void Page_Load(object sender, EventArgs e)
        {
            DataTable dt = default(DataTable);
            dt = CreateDataTable();
  
            //设置图表的数据源
            Chart1.DataSource = dt;
  
            //设置图表Y轴对应项
            Chart1.Series[0].YValueMembers = "Volume1";
            Chart1.Series[1].YValueMembers = "Volume2";
  
            //设置图表X轴对应项
            Chart1.Series[0].XValueMember = "Date";
              
            //绑定数据
            Chart1.DataBind();
        }
        private DataTable CreateDataTable()
        {
            //Create a DataTable as the data source of the Chart control
            DataTable dt = new DataTable();
  
            //Add three columns to the DataTable
            dt.Columns.Add("Date");
            dt.Columns.Add("Volume1");
            dt.Columns.Add("Volume2");
  
            DataRow dr;
  
            //Add rows to the table which contains some random data for demonstration
            dr = dt.NewRow();
            dr["Date"] = "Jan";
            dr["Volume1"] = 3731;
            dr["Volume2"] = 4101;
            dt.Rows.Add(dr);
  
            dr = dt.NewRow();
            dr["Date"] = "Feb";
            dr["Volume1"] = 6024;
            dr["Volume2"] = 4324;
            dt.Rows.Add(dr);
  
            dr = dt.NewRow();
            dr["Date"] = "Mar";
            dr["Volume1"] = 4935;
            dr["Volume2"] = 2935;
            dt.Rows.Add(dr);
  
            dr = dt.NewRow();
            dr["Date"] = "Apr";
            dr["Volume1"] = 4466;
            dr["Volume2"] = 5644;
            dt.Rows.Add(dr);
  
            dr = dt.NewRow();
            dr["Date"] = "May";
            dr["Volume1"] = 5117;
            dr["Volume2"] = 5671;
            dt.Rows.Add(dr);
  
            dr = dt.NewRow();
            dr["Date"] = "Jun";
            dr["Volume1"] = 3546;
            dr["Volume2"] = 4646;
            dt.Rows.Add(dr);
  
            return dt;
        }

  显示结果以柱状图为例,如下:

Chart控件的用法

这是本人初次使用Char控件的学习笔记,不喜勿喷,谢谢!!

软件开发技术交流,同学习共进步,欢迎加群, 群号:169600532