1

im making a system that requires something like stacked bar chart in c# i have searched for some stacked bar chart tutorial, experimented with codes and the like but it seems i cant come up to the output i want, most of the tutorials i searched are for basic bar chart. right now i did this in datagridview (colored cells) but it seems kinda foolish to make stacked bar chart out of a datagridview.

image link: http://tinypic.com/r/v8oe8k/8

heres my question, take a look at this picture, is this possible to do this in stacked bar chart?

1.) A series can continue to another column without the other stack from the first column? (Series 2)

2.) A series can stack over an empty space? (Series 5)

3.) if the two items above are possible, is this also possible for multi series bar chart? (optional)

if this is possible please do help me (providing a sample code snippet will be really be a big help)

thank you and have a nice day

edit: heres my code:

        chart1.Series.Add("Series 1");
        chart1.Series.Add("Series 2");
        chart1.Series.Add("Series 3");
        chart1.Series.Add("Series 4");
        chart1.Series.Add("Series 5");
        chart1.Series["Series 1"].ChartType = SeriesChartType.StackedColumn;
        chart1.Series["Series 2"].ChartType = SeriesChartType.StackedColumn;
        chart1.Series["Series 3"].ChartType = SeriesChartType.StackedColumn;
        chart1.Series["Series 4"].ChartType = SeriesChartType.StackedColumn;
        chart1.Series["Series 5"].ChartType = SeriesChartType.StackedColumn;

        chart1.Series["Series 1"].Points.AddXY(1, 50);
        chart1.Series["Series 2"].Points.AddXY(1, 100);
        chart1.Series["Series 2"].Points.AddXY(2, 50);
        chart1.Series["Series 3"].Points.AddXY(2, 200);            
        chart1.Series["Series 3"].Points.AddXY(3, 100);
        chart1.Series["Series 4"].Points.AddXY(3, 50);
        chart1.Series["Series 5"].Points.AddXY(5, 150);
Blitz
  • 23
  • 1
  • 4
  • Hi Blitz, welcome to SO, can you post what code you have so far? – Fiver Feb 24 '14 at 00:42
  • hi @Fiver thanks,i added my current code to the questio, ive tried to add different data to other columns using same series – Blitz Feb 24 '14 at 01:18

2 Answers2

1

To remove the empty space you must have identical number of points in all series for every X value :

    chart1.Series["Series 1"].Points.AddXY(1, 50);
    chart1.Series["Series 2"].Points.AddXY(1, 100);
    chart1.Series["Series 3"].Points.AddXY(1, 0);   
    chart1.Series["Series 4"].Points.AddXY(1, 0);
    chart1.Series["Series 5"].Points.AddXY(1, 0); 

    chart1.Series["Series 1"].Points.AddXY(2, 0);     
    chart1.Series["Series 2"].Points.AddXY(2, 50);
    chart1.Series["Series 3"].Points.AddXY(2, 200);   
    chart1.Series["Series 4"].Points.AddXY(2, 0); 
    chart1.Series["Series 5"].Points.AddXY(2, 0); 

    chart1.Series["Series 1"].Points.AddXY(3, 0);
    chart1.Series["Series 2"].Points.AddXY(3, 0);         
    chart1.Series["Series 3"].Points.AddXY(3, 100);
    chart1.Series["Series 4"].Points.AddXY(3, 50);
    chart1.Series["Series 5"].Points.AddXY(3, 0);

    chart1.Series["Series 1"].Points.AddXY(5, 0);
    chart1.Series["Series 2"].Points.AddXY(5, 0);
    chart1.Series["Series 3"].Points.AddXY(5, 0);
    chart1.Series["Series 4"].Points.AddXY(5, 0);
    chart1.Series["Series 5"].Points.AddXY(5, 150);
-1

Try creating a custom control to draw the bar graph. Look up some tutorials on creating your own controls. Then override the control's paint and draw your chart.

Custom Control Tutorial: http://techymedia.com/post/2013/04/21/How-to-create-custom-Control-In-C-Sharp-Tutorial-Step-By-Step.aspx (On creating a control, you can add your own variables and then draw the chart in the paint method.)

Graph Control: http://www.codeproject.com/Articles/5431/A-flexible-charting-library-for-NET

Captain Picard
  • 119
  • 4
  • 12