You are on page 1of 1

How to make stacked column chart

By Mihir Soni in the ASP.NET forum. 13-Feb-11 11:49 PM


Hello . Here i have taken small example which is used to draw stack chart.
DataTable dtTest; private void Form1_Load(System.Object sender, System.EventArgs e) { //Me.WindowState = FormWindowState.Maximized dtTest = new DataTable(); dtTest.Columns.Add("_Year", typeof(int)); dtTest.Columns.Add("_Month", typeof(int)); dtTest.Columns.Add("ManualInvoices", typeof(int)); dtTest.Columns.Add("AutoInvoices", typeof(int)); Random rndm = new Random(); for (int y = 2009; y <= 2010; y++) { for (int i = 1; i <= 12; i++) { dtTest.Rows.Add(y, i, rndm.Next(20000, 30001), rndm.Next(20000, 30001)); } } Chart1.Series.RemoveAt(0); Chart1.DataBindCrossTable(dtTest.AsEnumerable, "_Year", "_Month", "ManualInvoices,AutoInvoices", null); foreach (Series s in Chart1.Series) { s.ChartType = SeriesChartType.StackedColumn; s.IsValueShownAsLabel = true; s.IsXValueIndexed = true; } Chart1.ChartAreas(0).AxisX.Title = "Month"; Chart1.ChartAreas(0).AxisX.Interval = 1; Chart1.ChartAreas(0).AxisY.Title = "Invoices"; }

You might also like