Page 1 of 1
Stacked Bar Chart 100 percent with multiple bars
Posted: Tue Jun 18, 2013 8:09 pm
by 15665996
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 (37.3 KiB) Viewed 6808 times
Re: Stacked Bar Chart 100 percent with multiple bars
Posted: Wed Jun 19, 2013 4:22 pm
by 10050769
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,
Re: Stacked Bar Chart 100 percent with multiple bars
Posted: Tue Jun 25, 2013 6:29 pm
by 15665996
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.
Re: Stacked Bar Chart 100 percent with multiple bars
Posted: Wed Jun 26, 2013 11:02 am
by 10050769
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,