BarChart控件的使用

The HTML Markup

<asp:BarChart ID="BarChart1" runat="server" ChartHeight="300" ChartWidth="450" ChartType="Column"

                ChartTitle="United States versus European,England Widget Production"

                ChartTitleColor="#0E426C" CategoryAxisLineColor="#D08AD9"

                ValueAxisLineColor="#D08AD9" BaseLineColor="#A156AB" >

            <Series>

                 <asp:BarChartSeries Name="United States" BarColor="#6C1E83" />

                <asp:BarChartSeries Name="Europe" BarColor="#D08AD9"/>

                <asp:BarChartSeries Name="England" BarColor="Bule"/>

            </Series>

        </asp:BarChart>

The code behind page

  System.Data.DataTable dt = new System.Data.DataTable();

            dt.Columns.Add("Date");

            dt.Columns.Add("UnitedStates");

            dt.Columns.Add("Europe");

            dt.Columns.Add("England");

            dt.Rows.Add("2007", "20", "24", "56");

            dt.Rows.Add("2008", "47", "67", "39");

            dt.Rows.Add("2009", "55", "16", "78");

            string[] x = new string[dt.Rows.Count];

            decimal[] y1 = new decimal[dt.Rows.Count];

            decimal[] y2 = new decimal[dt.Rows.Count];

            decimal[] y3 = new decimal[dt.Rows.Count];

            for (int i = 0; i < dt.Rows.Count; i++)

            {



                x[i] = dt.Rows[i]["Date"].ToString();

                y1[i] = Convert.ToDecimal(dt.Rows[i]["UnitedStates"]);

                y2[i] = Convert.ToDecimal(dt.Rows[i]["Europe"]);

                y3[i] = Convert.ToDecimal(dt.Rows[i]["England"]);



            }

            BarChart1.CategoriesAxis = String.Join(",", x);

            BarChart1.Series[0].Data = y1;

            BarChart1.Series[1].Data = y2;

            BarChart1.Series[2].Data = y3;

 

你可能感兴趣的:(chart)