vs2010 + .net3.5 MSCharts使用介绍与例子

MSCharts,以图形化方式展示数据,


首先
下载Microsoft Chart Controls for Microsoft .NET Framework 3.5:

点击下载

安装完成之后;


在vs2010中添加控件

 


添加完之后就可以拖控件的方式添加Charts


例子:

 

以上饼图的aspx代码

        <asp:Chart ID="Chart1" runat="server" Width="500px" Height="300px">
            <Titles>
                <asp:Title Name="DefaultTitle" Font="Trebuchet MS, 10pt, style=Bold"
                      Text = "My Title"  Visible="true" />
             </Titles>
            <legends>
                <asp:Legend BackColor="Transparent" Alignment="Center" Docking="Right" LegendStyle="Table" Font="Trebuchet MS, 7.5pt, style=Bold" IsTextAutoFit="False" Name="Default" ></asp:Legend>
            </legends>
            <series>
                <asp:Series Name="Series1">
                </asp:Series>
            </series>
            <chartareas>
                <asp:ChartArea Name="ChartArea1">
                </asp:ChartArea>
            </chartareas>
        </asp:Chart>

 

CS代码

 protected void Page_Load(object sender, EventArgs e)
        {
            DataTable dt = FillData();
            DataView dv = dt.DefaultView;
            Chart1.Series["Series1"].Points.DataBindXY(dv, "Name", dv, "Count");

            //Set the chart type  

            Chart1.Series["Series1"].ChartType = SeriesChartType.Pie;

            // Set the bar width  
            Chart1.Series["Series1"]["PointWidth"] = "0.5";


            // Show data points labels  
            Chart1.Series["Series1"].IsValueShownAsLabel = true;

            // Set data points label style  
            Chart1.Series["Series1"]["BarLabelStyle"] = "Center";

            Chart1.Series["Series1"].Label = "#PERCENT";
            Chart1.Series["Series1"].LegendText = "#AXISLABEL";

            Chart1.Series["Series1"]["PieLabelStyle"] = "Outside";

            // Show chart as 3D  
            Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;
            Chart1.ChartAreas["ChartArea1"].Area3DStyle.WallWidth = 10;

            // Draw chart as 3D Cylinder  
            Chart1.Series["Series1"]["DrawingStyle"] = "Cylinder";

        }

        private DataTable FillData()
        {
            DataTable dt = new DataTable();
            DataColumn dc;

            dc = new DataColumn();
            dc.ColumnName = "Name";
            dt.Columns.Add(dc);
            dc = new DataColumn();
            dc.ColumnName = "Count";
            dt.Columns.Add(dc);

            DataRow dr;
            dr = dt.NewRow();
            dr["Name"] = "Fred";
            dr["Count"] = "54";
            dt.Rows.Add(dr);
            dr = dt.NewRow();
            dr["Name"] = "Bill";
            dr["Count"] = "66";
            dt.Rows.Add(dr);
            dr = dt.NewRow();
            dr["Name"] = "Rhona";
            dr["Count"] = "32";
            dt.Rows.Add(dr);

            return dt;
        }

 

参考资料:
http://weblogs.asp.net/scottgu/archive/2008/11/24/new-asp-net-charting-control-lt-asp-chart-runat-quot-server-quot-gt.aspx

posted on 2012-05-03 15:52  向振文  阅读(1335)  评论(0编辑  收藏  举报