Shift 100% Stacked Bar Graph
Shift 100% Stacked Bar Graph
I am trying this using designer only .
1) Is it possible to shift bar graph left ?
2) Can i remove 0 gridline ( bottom most) gridline and show 100% gridline
[img] [/img]
Source code : https://github.com/dekajp/DealViewChart ... esigner.cs
1) Is it possible to shift bar graph left ?
2) Can i remove 0 gridline ( bottom most) gridline and show 100% gridline
[img] [/img]
Source code : https://github.com/dekajp/DealViewChart ... esigner.cs
Last edited by rpt on Thu Aug 25, 2016 1:07 pm, edited 1 time in total.
-
- Guru
- Posts: 1603
- Joined: Fri Nov 15, 2002 12:00 am
Re: Sift 100% Stacked Bar Graph
Hello,
I think I can achieve what you're looking for with code like the following:
I think I can achieve what you're looking for with code like the following:
Code: Select all
Form1 form;
private void button5_Click(object sender, EventArgs e)
{
form = new Form1();
form.tChart1.Axes.Bottom.SetMinMax(1, 2);
form.tChart1.GetNextAxisLabel += TChart1_GetNextAxisLabel;
form.ShowDialog();
}
private void TChart1_GetNextAxisLabel(object sender, GetNextAxisLabelEventArgs e)
{
if (((Steema.TeeChart.Axis)sender).Equals(form.tChart1.Axes.Right)) e.Stop = false;
switch (e.LabelIndex)
{
case 0: e.LabelValue = 25; break;
case 1: e.LabelValue = 50; break;
case 2: e.LabelValue = 75; break;
default: e.Stop = true; break;
}
}
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: Shift 100% Stacked Bar Graph
thanks chris
This seems to be working . I see that SetMinMax doing the spacing and Event for Axis label is removing 0 value axis line.
This seems to be working . I see that SetMinMax doing the spacing and Event for Axis label is removing 0 value axis line.
Re: Shift 100% Stacked Bar Graph
Is there a Way to get bounds of bar .
But How do i get Bar Bounds of First Column and Second Column for each Bar
Code: Select all
void AmortizationGraphTen_AfterDraw(object sender, Graphics3D g)
{
TChart tChart1 = (TChart)sender;
foreach (Series sbar in tChart1.Series)
{
try
{
Bar bar1 = (Bar)sbar;
Rectangle barBound = bar1.BarBounds; // Why always last column ?
int xFirst = bar1.CalcXPos(0) ;
int yFirst = bar1.CalcYPos(0);
// How to check if this does not exists
int xSecond = bar1.CalcXPos(1);
int ySecond = bar1.CalcYPos(1);
Point start = new Point(xFirst + barBound.Width, yFirst);
Point startDown = new Point(xFirst + barBound.Width, yFirst + barBound.Height);
Point DownToRight = new Point(xSecond, ySecond + barBound.Height);
Point RightToUp = new Point(xSecond, ySecond);
Point UpToStart = start;
Point[] curvePoints = { start, startDown, DownToRight, RightToUp, start };
SolidBrush blueBrush = new SolidBrush(Color.Blue);
g.GDIplusCanvas.FillPolygon(blueBrush, curvePoints);
//g.MoveTo(new Point(xFirst,yFirst));
//g.LineTo(new Point(xSecond, ySecond),0);
}
catch (Exception ex)
{
}
}
}
Re: Shift 100% Stacked Bar Graph
I am able to acheive what i need by deriving Bar Class. As you can see in the image. But i want to achive this in After Draw event.
Is this possible in After draw event . If No , then i would like to use TEN file and load this class. but every time i try to do . I am getting reflection error.
Is this possible in After draw event . If No , then i would like to use TEN file and load this class. but every time i try to do . I am getting reflection error.
Code: Select all
namespace Steema.TeeChart.Styles
{
public class AmortBar : Bar
{
public AmortBar()
: base()
{
}
Rectangle PreviousBarBound;
public override void DrawBar(int barIndex, int startPos, int endPos)
{
base.DrawBar(barIndex, startPos, endPos);
Rectangle current;
if (barIndex == 0)
{
PreviousBarBound = this.BarBounds;
}
if (barIndex == 1)
{
current = this.BarBounds;
Point start = new Point(PreviousBarBound.X +PreviousBarBound.Width, PreviousBarBound.Y);
Point startDown = new Point(PreviousBarBound.X + PreviousBarBound.Width, PreviousBarBound.Y + PreviousBarBound.Height);
Point DownToRight = new Point(current.X, current.Y+current.Height);
Point RightToUp = new Point(current.X, current.Y);
Point UpToStart = start;
Point[] curvePoints = { start, startDown, DownToRight, RightToUp, start };
Color Soft = Color.FromArgb(80, this.Color);
SolidBrush blueBrush = new SolidBrush(Soft);
this.Chart.Graphics3D.GDIplusCanvas.FillPolygon(blueBrush, curvePoints);
}
}
}
}
- Attachments
-
- untitled.png (40.1 KiB) Viewed 20013 times
Re: Shift 100% Stacked Bar Graph
Hello,
Here's a coded example.
Regards,
Marc Meumann
Here's a coded example.
Code: Select all
private void Form1_Load(object sender, EventArgs e)
{
bar1.MultiBar = MultiBars.Stacked;
bar1.Add(3);
bar1.Add(4);
bar2.Add(5);
bar2.Add(2);
bar3.Add(2);
bar3.Add(3);
bar1.BarWidthPercent = 30;
bar2.BarWidthPercent = 30;
bar3.BarWidthPercent = 30;
}
private void tChart2_AfterDraw(object sender, Graphics3D g)
{
for (int s = 0; s < tChart2.Series.Count; s++)
{
Point[] poly = new Point[4];
for (int i = 0; i < tChart2.Series[0].Count; i++)
{
Bar aBar = ((Bar)tChart2[s]);
{
if (i == 0)
{
if (s == 0)
poly[0] = new Point(aBar.CalcXPos(i) + aBar.BarBounds.Width, tChart2.Axes.Bottom.Position);
else
poly[0] = new Point(aBar.CalcXPos(i) + aBar.BarBounds.Width, ((Bar)tChart2[s-1]).CalcYPos(i));
poly[1] = new Point(aBar.CalcXPos(i) + aBar.BarBounds.Width, aBar.CalcYPos(i));
}
else
{
poly[2] = new Point(aBar.CalcXPos(i), aBar.CalcYPos(i));
if (s == 0)
poly[3] = new Point(aBar.CalcXPos(i), tChart2.Axes.Bottom.Position);
else
poly[3] = new Point(aBar.CalcXPos(i), ((Bar)tChart2[s - 1]).CalcYPos(i));
}
}
g.Pen.Visible = false;
g.Brush.Color = aBar.Color;
g.Brush.Transparency = 50;
}
g.ClipRectangle(tChart2.Chart.ChartRect); //don't paint polygon out of bounds on zooms
g.Polygon(poly);
g.UnClip();
}
}
Marc Meumann
Steema Support
Re: Shift 100% Stacked Bar Graph
Thank You , this worked.
Re: Shift 100% Stacked Bar Graph
marc
Can you explain me how you got the stacked graph that wide ? Below is my graph and i am using
I want to shift Current to right and increase the Gap in between 2 stacks like you have in above post.
Can you explain me how you got the stacked graph that wide ? Below is my graph and i am using
Code: Select all
tChart1.Axes.Bottom.SetMinMax(1,2);
-
- Guru
- Posts: 1603
- Joined: Fri Nov 15, 2002 12:00 am
Re: Shift 100% Stacked Bar Graph
Are you using the same overload of the Series.Add() method that Marc is using in his code?rpt wrote: Can you explain me how you got the stacked graph that wide ? Below is my graph and i am using
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: Shift 100% Stacked Bar Graph
I am using Ten config file.
Here is the code -
https://github.com/dekajp/TeeChart-for- ... edBars2.cs
Here is the Github repo . https://github.com/dekajp/TeeChart-for- ... ms-samples
Here is the code -
Code: Select all
StackedBars2.cs
Here is the Github repo . https://github.com/dekajp/TeeChart-for- ... ms-samples