Stacked Bar for Horizontal
Stacked Bar for Horizontal
would like to know to can I set horizontal stacked bar chart as attached image.
i cant seems to get the stacked to work correctly.
i cant seems to get the stacked to work correctly.
- Attachments
-
- TeeChart-BarStacked.PNG (15.99 KiB) Viewed 21660 times
-
- Guru
- Posts: 1603
- Joined: Fri Nov 15, 2002 12:00 am
Re: Stacked Bar for Horizontal
Well, some code to help you get started would be something like this:bpamit wrote:would like to know to can I set horizontal stacked bar chart as attached image.
i cant seems to get the stacked to work correctly.
Code: Select all
private void InitializeChart()
{
Random rnd = new Random();
tChart1.Header.Text = "My Chart";
for (int i = 0; i < 3; i++)
{
HorizBar series = new HorizBar(tChart1.Chart);
series.Title = "My Horizontal " + (i + 1).ToString();
for (int t = 0; t < 3; t++)
{
series.Add(rnd.Next(200), (t + 1).ToString() + "Y");
}
series.Marks.Style = MarksStyles.Value;
series.MultiBar = MultiBars.Stacked;
series.MarksOnBar = true;
}
tChart1.Axes.Left.Labels.Style = AxisLabelStyle.Text;
tChart1.Axes.Left.Grid.Visible = false;
tChart1.Axes.Bottom.Grid.Visible = true;
}
Best Regards,
Christopher Ireland / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
Re: Stacked Bar for Horizontal
Hi Christopher, thanks for the prompt reply. I managed to get the chart working.
But I having issue to set the chart to start at a specific value instead of 0.
Please refer to the attachment. Thanks.
But I having issue to set the chart to start at a specific value instead of 0.
Please refer to the attachment. Thanks.
- Attachments
-
- TeeChart-StackedBar2.png (24.63 KiB) Viewed 21627 times
-
- Guru
- Posts: 1603
- Joined: Fri Nov 15, 2002 12:00 am
Re: Stacked Bar for Horizontal
Many apologies for the delay in response to this question - do you still need help in this area?
Best Regards,
Christopher Ireland / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
Re: Stacked Bar for Horizontal
Hi Christopher, Yes I still cannot figure it out. Thanks.
-
- Guru
- Posts: 1603
- Joined: Fri Nov 15, 2002 12:00 am
Re: Stacked Bar for Horizontal
Hello!
Okay, well, taking your data set I've been able to come up with the following code:
This gives me the following chart:
I would suggest this chart is correct - take the "1Y" row - this correctly reflects the sum of the 1Y data (26.3) and also reflects the first data point accurately on the bar (2.145). All the rows (1Y->10Y) are correct in this sense also. Would you agree that this chart is correct? If so, what chart would you like to see if it is not this one?
Okay, well, taking your data set I've been able to come up with the following code:
Code: Select all
private void InitializeChart()
{
double[] YearOne = new double[] { 2.145, 4.132, 4.409, 15.614 };
double[] YearThree = new double[] { 3.632, 4.509, 4.8008, 7.162 };
double[] YearFive = new double[] { 3.806, 4.478, 4.743, 5.941 };
double[] YearSeven = new double[] { 4.105, 4.439, 4.729, 5.912 };
double[] YearTen = new double[] { 4.124, 4.492, 4.773, 5.599 };
string[] labels = new string[] { "1Y", "3Y", "5Y", "7Y", "10Y" };
List<double[]> years = new List<double[]>() { YearOne, YearThree, YearFive, YearSeven, YearTen };
void AddBar(int index)
{
HorizBar bar = new HorizBar(tChart1.Chart);
bar.Title = "My Horizontal " + (index + 1).ToString();
for (int i = 0; i < years.Count; i++)
{
bar.Add(years[i][index], labels[i]);
}
bar.MultiBar = MultiBars.Stacked;
bar.Marks.Style = MarksStyles.Value;
bar.MarksOnBar = true;
}
for (int i = 0; i < 4; i++)
{
AddBar(i);
}
tChart1.Axes.Left.Labels.Style = AxisLabelStyle.Text;
tChart1.Axes.Left.Grid.Visible = false;
tChart1.Axes.Bottom.Grid.Visible = true;
}
Best Regards,
Christopher Ireland / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
Re: Stacked Bar for Horizontal
Hi Christopher, chart is incorrect. I would like to start the chart for 1Y at 2.145, 3Y at 3.3632 and 5Y at 3.806. please refer to the first image. Your sample is all starting from 0.
-
- Guru
- Posts: 1603
- Joined: Fri Nov 15, 2002 12:00 am
Re: Stacked Bar for Horizontal
Yes, and this is correct if each point is a *value*.bpamit wrote:Hi Christopher, chart is incorrect. I would like to start the chart for 1Y at 2.145, 3Y at 3.3632 and 5Y at 3.806. please refer to the first image. Your sample is all starting from 0.
Code: Select all
double[] YearOne = new double[] { 2.145, 4.132, 4.409, 15.614 };
Another, quite different, type of chart is where the points form a *range*. In these charts there are two points, the start point of the range and the end point of the range. So, for example, in the YearOne array above we could say there are two ranges:
2.145 -> 4.132
4.409 -> 15.614
or we could say there are three ranges:
2.145 -> 4.132
4.132 -> 4.409
4.409 -> 15.614
so the question is - are the points in the YearOne, YearTwo etc. arrays of my example *values* or *ranges*? The chart that my example drew is correct if the points are *values*. If the points are *ranges*, however, a completely different series type has to be used.
Best Regards,
Christopher Ireland / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
Re: Stacked Bar for Horizontal
Hi Christopher, my bad. Now I understand what you mean. I would like to know which chart type to use if I need to draw bar in range.
-
- Guru
- Posts: 1603
- Joined: Fri Nov 15, 2002 12:00 am
Re: Stacked Bar for Horizontal
No problem - one way of drawing a horizontal range chart is to use the Gantt series, e.g.bpamit wrote:Hi Christopher, my bad. Now I understand what you mean. I would like to know which chart type to use if I need to draw bar in range.
Code: Select all
private void InitializeChart()
{
double[] YearOne = new double[] { 2.145, 4.132, 4.409, 15.614 };
double[] YearThree = new double[] { 3.632, 4.509, 4.8008, 7.162 };
double[] YearFive = new double[] { 3.806, 4.478, 4.743, 5.941 };
double[] YearSeven = new double[] { 4.105, 4.439, 4.729, 5.912 };
double[] YearTen = new double[] { 4.124, 4.492, 4.773, 5.599 };
string[] labels = new string[] { "1Y", "3Y", "5Y", "7Y", "10Y" };
Color[] colors = new Color[] { Color.Red, Color.Orange, Color.Yellow, Color.Green, Color.Blue };
List<double[]> years = new List<double[]>() { YearOne, YearThree, YearFive, YearSeven, YearTen };
Gantt bar = new Gantt(tChart1.Chart);
bar.XValues.DateTime = false;
bar.Pointer.VertSize = 20;
bar.Marks.Visible = true;
bar.Marks.Style = MarksStyles.Value;
tChart1.Legend.Visible = false;
tChart1.Axes.Left.MinimumOffset = 25;
tChart1.Axes.Left.MaximumOffset = 25;
tChart1.Axes.Bottom.Labels.Separation = 0;
tChart1.Axes.Bottom.Increment = 1;
void AddBar(int index)
{
double[] values = years[index];
for (int i = 0; i < values.Length - 1; i++)
{
bar.Add(values[i], values[i + 1], index, labels[index], colors[i]);
}
}
for (int i = 0; i < 5; i++)
{
AddBar(i);
}
}
Best Regards,
Christopher Ireland / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
Re: Stacked Bar for Horizontal
Hi Christopher, thanks for the codes. It works.