[置顶] [MSCHART]柱状图

后台代码:

    private void DataBind() 
    {
        ProductByYear py = new ProductByYear();
        for (int i = 0; i < RadioButtonList1.Items.Count; i++)
        {
            if (RadioButtonList1.Items[i].Selected)
            {

                py.Company = RadioButtonList1.Items[i].Value.Trim();
            }
        }
        //py.Company = "ZE";
        ProductByYearManager pymgr = new ProductByYearManager();
        this.Store1.DataSource = pymgr.ProductByYearList(py);
        this.Store1.DataBind();

        this.ChartYear.Width = 600;
        this.ChartYear.Height = 400;
        this.ChartYear.DataSource = pymgr.ProductByYearChart(py);
        this.ChartYear .DataBind ();
        this.ChartYear.Series["last year"].ChartType = SeriesChartType.Column;
        this.ChartYear.Series["year"].ChartType = SeriesChartType.Column;
        this.ChartYear.Series["year"].XValueMember = "产品类别";
        this.ChartYear.Series["year"].YValueMembers = "本年度金额";
        this.ChartYear.Series["last year"].XValueMember = "产品类别";
        this.ChartYear.Series["last year"].YValueMembers = "上一年度金额";

        //显示数据
        ChartYear.Series["year"].IsValueShownAsLabel = true;
        ChartYear.Series["last year"].IsValueShownAsLabel = true;

        this.ChartYear.Legends[0].Enabled = true;
      
        //this.ChartYear.ChartAreas["ChartArea1"].AxisX.Title = "产品类型";
        this.ChartYear.ChartAreas["ChartArea1"].AxisY.Title = "销售金额";
        //背景色设置
        this.ChartYear.ChartAreas["ChartArea1"].ShadowColor = Color.Transparent;
        this.ChartYear.ChartAreas["ChartArea1"].BackColor = Color.FromArgb(209, 237, 254);         //该处设置为了由天蓝到白色的逐渐变化
        this.ChartYear.ChartAreas["ChartArea1"].BackGradientStyle = GradientStyle.TopBottom;
        this.ChartYear.ChartAreas["ChartArea1"].BackSecondaryColor = Color.White;

        //中间X,Y线条的颜色设置
        this.ChartYear.ChartAreas["ChartArea1"].AxisX.MajorGrid.LineColor = Color.FromArgb(64, 64, 64, 64);
        this.ChartYear.ChartAreas["ChartArea1"].AxisY.MajorGrid.LineColor = Color.FromArgb(64, 64, 64, 64);
        //X.Y轴数据显示间隔
   
        this.ChartYear.DataBind(); 

    }

前台代码:

                              <asp:Chart ID="ChartYear" runat="server"  BackColor="LightSteelBlue" 
                                BackGradientStyle="TopBottom" BackSecondaryColor="AliceBlue"  EnableTheming="False" 
                                EnableViewState="True">
                                 <Titles>
                                 <asp:Title  Font="微软雅黑, 16pt" Text="本年度VS上一年度销售额(单位:10万)" Alignment="TopCenter"></asp:Title>
			                    <asp:Title Docking="Bottom" Font="Trebuchet MS, 8.25pt" 
                                                        Text="Zettlercn Corporation" Alignment="MiddleRight"></asp:Title>
                                </Titles>
                                   <legends>
			                                    <asp:Legend BackColor="Transparent" Alignment="Center" Docking="Bottom" Font="Trebuchet MS, 8.25pt, style=Bold" IsTextAutoFit="False" Name="Default" LegendStyle="Row"></asp:Legend>
		                            </legends>
                                <Series>
                                    <asp:Series Name="year" >
                                    </asp:Series>
                                    <asp:Series Name="last year" >
                                    </asp:Series>
                                </Series>
                                <ChartAreas>
                                    <asp:ChartArea Name="ChartArea1">
                                    </asp:ChartArea>
                                </ChartAreas>
                            </asp:Chart>


图:

[置顶] [MSCHART]柱状图_第1张图片

你可能感兴趣的:(server,asp,微软,产品,alignment)