Asp:chart 控件画柱状图和饼图

转: http://blog.csdn.net/liudongyue1987/article/details/4674530#comments        
  HTML部分:

        <asp:Chart ID="ChartBar" runat="server" Width="800px"   BackColor="#FFFFCC" Palette="BrightPastel" BorderWidth = "2" BorderColor = "#cc9900" >
         <Legends>
                <asp:Legend IsTextAutoFit="False" Name="Default" BackColor="Transparent" Font="Trebuchet MS, 8.25pt, style=Bold">
                </asp:Legend>
            </Legends>
            <ChartAreas>
                <asp:ChartArea Name="ChartArea1">
                </asp:ChartArea>
            </ChartAreas>
        </asp:Chart>
        <asp:Chart ID="ChartPie" runat="server" Width="400px"   BackColor="#FFFFCC" Palette="BrightPastel" BorderWidth = "0" BorderColor = "#cc9900" >
            <Legends>
                <asp:Legend IsTextAutoFit="False" Name="Default" BackColor="Transparent" Font="Trebuchet MS, 8.25pt, style=Bold">
                </asp:Legend>
            </Legends>
            <ChartAreas>
                <asp:ChartArea Name="ChartArea1">
                </asp:ChartArea>
            </ChartAreas>
          
        </asp:Chart>

           C#部分:

            //获取每月销售情况
            int[] arraySell=new int[]{10};

            //获取月份
            string[] arrayMonths = new string[] { "1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月" };

            //获取部门
            string[] arrayDeparts = new string[] { "部门1", "部门2", "部门3" };

            Series seriess = new Series("销售情况");
            seriess.BorderWidth = 3;
            seriess.ShadowOffset = 2;

            Series seriesPies = new Series("销售情况");
            seriesPies.ChartType = SeriesChartType.Pie;
            seriesPies.BorderWidth = 3;
            seriesPies.ShadowOffset = 2;

            this.ChartBar.Series.Add(seriess);
            this.ChartPie.Series.Add(seriesPies);

            Title tBar = new Title("销售情况柱状图");
            this.ChartBar.Titles.Add(tBar);

            Title tPie = new Title("销售情况饼状图");
            this.ChartPie.Titles.Add(tPie);

            this.ChartBar.ChartAreas["ChartArea1"].AxisX.Interval = 1;//x轴数据显示间隔
            this.ChartBar.ChartAreas["ChartArea1"].AxisY.Interval = 50;

            //画柱状图

            foreach (string d in arrayDeparts)
            {
                Series tempseries = new Series(string.Format("{0}", d));
                this.ChartBar.Series.Add(tempseries);

                foreach (string m in arrayMonths)
                {
                    foreach (int n in arraySell)
                    {
                        tempseries.Points.AddXY(m, n);
                    }
                }
            }

            //画饼图

            foreach (string d in arrayDeparts)
            {
                foreach(int n in arraySell)
                {
                    seriesPies.Points.AddXY(d, n);
                }
            }


            this.ChartBar.ChartAreas["ChartArea1"].AxisX.IsMarginVisible = false;
            this.ChartBar.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = false;
            //背景色设置
            this.ChartBar.ChartAreas["ChartArea1"].ShadowColor = Color.Transparent;
            this.ChartBar.ChartAreas["ChartArea1"].BackColor = Color.Azure;
            this.ChartBar.ChartAreas["ChartArea1"].BackGradientStyle = GradientStyle.TopBottom;
            this.ChartBar.ChartAreas["ChartArea1"].BackSecondaryColor = Color.White;
            //X,Y坐标线颜色和大小
            this.ChartBar.ChartAreas["ChartArea1"].AxisX.LineColor = Color.Blue;
            this.ChartBar.ChartAreas["ChartArea1"].AxisY.LineColor = Color.Blue;
            this.ChartBar.ChartAreas["ChartArea1"].AxisX.LineWidth = 2;
            this.ChartBar.ChartAreas["ChartArea1"].AxisY.LineWidth = 2;
            this.ChartBar.ChartAreas["ChartArea1"].AxisY.Title = "销量";
            //中间X,Y线条的颜色设置
            this.ChartBar.ChartAreas["ChartArea1"].AxisX.MajorGrid.LineColor = Color.Blue;
            this.ChartBar.ChartAreas["ChartArea1"].AxisY.MajorGrid.LineColor = Color.Blue;
            //X.Y轴数据显示间隔
            this.ChartBar.ChartAreas["ChartArea1"].AxisX.Interval = 1;  //X轴数据显示间隔
            this.ChartBar.ChartAreas["ChartArea1"].AxisY.Interval = 50;
            //X轴线条显示间隔
            this.ChartBar.ChartAreas["ChartArea1"].AxisX.MajorGrid.Interval = 1;

 

效果

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值