mschart控制項的累計柱狀圖效果實現

來源:互聯網
上載者:User
private void Form1_Load(object sender, EventArgs e)
{
//定義一個表,並添加資料
DataTable tbl = new DataTable();

DataColumn c1 = new DataColumn("c1");
DataColumn c2 = new DataColumn("c2");
DataColumn c3 = new DataColumn("c3");
tbl.Columns.Add(c1);
tbl.Columns.Add(c2);
tbl.Columns.Add(c3);

DataRow r1 = tbl.NewRow();
r1["c1"] = "china";
r1["c2"] = 60;
r1["c3"] = 20;
tbl.Rows.Add(r1);

DataRow r2 = tbl.NewRow();
r2["c1"] = "america";
r2["c2"] = 10;
r2["c3"] = 5;
tbl.Rows.Add(r2);



Series series1 = new Series();
series1.ChartType = SeriesChartType.StackedColumn;
Chart1.Series.Add(series1);
Series series2 = new Series();
series2.ChartType = SeriesChartType.StackedColumn;
Chart1.Series.Add(series2);

Chart1.Series[0].Points.DataBind(tbl.DefaultView, "c1", "c2", "");
Chart1.Series[1].Points.DataBind(tbl.DefaultView, "c1", "c3", "");

Chart1.Series[0].Name = "Rank A";
Chart1.Series[1].Name = "Rank B";

Chart1.Series[0].IsValueShownAsLabel = true;
Chart1.Series[1].IsValueShownAsLabel = true;
Chart1.ChartAreas[0].Area3DStyle.Enable3D = true;



/*刪除下面,才能實現累計柱狀圖(1),否則效果(2)
目前還沒看懂關於Series對象方括弧中的這個所謂的自訂屬性*/

//foreach (Series s in Chart1.Series)
//{
// s["StackedGroupName"] = s.Name;
//}

}

 

圖1  累計柱狀圖效果

圖2  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.