Page 1 of 1
Shift 100% Stacked Bar Graph
Posted: Wed Aug 24, 2016 2:51 pm
by 9642129
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]
- Amortization Graph.png (60.84 KiB) Viewed 19981 times
[/img]
Source code :
https://github.com/dekajp/DealViewChart ... esigner.cs
Re: Sift 100% Stacked Bar Graph
Posted: Thu Aug 25, 2016 9:04 am
by Christopher
Hello,
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;
}
}
Re: Shift 100% Stacked Bar Graph
Posted: Thu Aug 25, 2016 1:14 pm
by 9642129
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.
Re: Shift 100% Stacked Bar Graph
Posted: Wed Nov 30, 2016 2:43 pm
by 9642129
Is there a Way to get bounds of 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)
{
}
}
}
But How do i get Bar Bounds of First Column and Second Column for each Bar
Re: Shift 100% Stacked Bar Graph
Posted: Wed Nov 30, 2016 7:26 pm
by 9642129
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.
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);
}
}
}
}
Re: Shift 100% Stacked Bar Graph
Posted: Thu Dec 01, 2016 3:32 pm
by Marc
Hello,
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();
}
}
- BarPolyFill.png (8.86 KiB) Viewed 19846 times
Regards,
Marc Meumann
Re: Shift 100% Stacked Bar Graph
Posted: Thu Dec 01, 2016 7:30 pm
by 9642129
Thank You , this worked.
Re: Shift 100% Stacked Bar Graph
Posted: Thu Jan 05, 2017 7:19 pm
by 9642129
marc
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);
- Untitled.png (5.69 KiB) Viewed 19754 times
I want to shift Current to right and increase the Gap in between 2 stacks like you have in above post.
Re: Shift 100% Stacked Bar Graph
Posted: Mon Jan 09, 2017 11:41 am
by Christopher
rpt wrote:
Can you explain me how you got the stacked graph that wide ? Below is my graph and i am using
Are you using the same overload of the Series.Add() method that Marc is using in his code?
Re: Shift 100% Stacked Bar Graph
Posted: Mon Jan 09, 2017 7:37 pm
by 9642129