Stacked Bar Chart 100 percent with multiple bars

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
phil1995
Newbie
Newbie
Posts: 3
Joined: Tue May 21, 2013 12:00 am

Stacked Bar Chart 100 percent with multiple bars

Post by phil1995 » Tue Jun 18, 2013 8:09 pm

I have a need from a customer to produce a bar chart that totals up the passed/failed/undetermined status for daily shipments. In the past we have used a 100% stacked bar chart that has worked well. My customer wold not like to see three bars for each date, all using the 100% stacked method. How can I display three separate bars for each date.

For example the data may look like shown below for each day:

Day-------------------- Cat1Pass Cat1Fail Cat1Und Cat2Pass Cat2Fail Cat2Und Cat3Pass Cat3Fail Cat3Und
1 May 2013---------------------5----------3--------2----------8--------2----------3---------9----------2--------9

The chart needs to look similar to the image below, but with 3 bars.
stacked.png
stacked.png (37.3 KiB) Viewed 6813 times

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Stacked Bar Chart 100 percent with multiple bars

Post by Sandra » Wed Jun 19, 2013 4:22 pm

Hello phil1995,

I think you can do something as next code where I use a StackGroup property:

Code: Select all

        private void InitializeChart()
        {
          tChart1.Aspect.View3D = false;
          Random rnd = new Random(); 
          for (int i = 0; i < 4; i++)
          {
            Steema.TeeChart.Styles.Bar series1= new Steema.TeeChart.Styles.Bar(tChart1.Chart);
            series1.BarStyle = BarStyles.RectGradient;
            series1.Gradient.Direction = LinearGradientMode.Horizontal;
            if (i % 2 == 0)
            {
              series1.StackGroup = 0;
              series1.MultiBar = MultiBars.Stacked; 
            }
            else
            {
              series1.StackGroup = 1;
              series1.MultiBar = MultiBars.Stacked; 
            }
            DateTime dt = DateTime.Now; 
            for (int j = 0; j < 10; j++)
            {
              series1.Add(dt, rnd.Next(100)); 
                dt = dt.AddDays(1); 
            }
          }
          
        }
Could you tell us if previous code works in your end?

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

phil1995
Newbie
Newbie
Posts: 3
Joined: Tue May 21, 2013 12:00 am

Re: Stacked Bar Chart 100 percent with multiple bars

Post by phil1995 » Tue Jun 25, 2013 6:29 pm

Thanks for that. The StackGroup property did the trick. The only issue I had was that if NULL values were associated with any of the series, the stacks were added to the wrong group. I changed my data to use zeros instead on Null values, and it seems to work fine. Thanks for your help.

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Stacked Bar Chart 100 percent with multiple bars

Post by Sandra » Wed Jun 26, 2013 11:02 am

Hello phil1995,

I am glad our suggestion has helped you. On the other hand, I think a good solution that allow you work with Null values and stackgroup, is use color transparent for the points you want be null. You can do something as next:

Code: Select all

    public Form1()
    {
      InitializeComponent();
      InitializeChart();    
    }
    private void InitializeChart()
    {
      tChart1.Aspect.View3D = false;
      Random rnd = new Random();
      for (int i = 0; i < 4; i++)
      {
        Steema.TeeChart.Styles.Bar series1 = new Steema.TeeChart.Styles.Bar(tChart1.Chart);
        series1.BarStyle = BarStyles.RectGradient;
        series1.Gradient.Direction = LinearGradientMode.Horizontal;
        //Assign group.
        if (i % 2 == 0)
        {
          series1.StackGroup = 0;
          series1.MultiBar = MultiBars.Stacked;
        }
        else
        {
          series1.StackGroup = 1;
          series1.MultiBar = MultiBars.Stacked;
        }
        //populate seires.
        DateTime dt = DateTime.Now;
        for (int j = 0; j < 10; j++)
        {
          if (i % 2 == 0)
          {
            if (j == 0 || j == 1)
            {
              series1.Add(dt, 0,Color.Transparent);
              dt = dt.AddDays(1);
            }
            else
            {
              series1.Add(dt, rnd.Next(100));
              dt = dt.AddDays(1);
            }
          }
          else
          {
            series1.Add(dt, rnd.Next(100));
            dt = dt.AddDays(1);
          }
        }
      }
    }
Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply