Shift 100% Stacked Bar Graph

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
rpt
Newbie
Newbie
Posts: 24
Joined: Wed Aug 09, 2006 12:00 am

Shift 100% Stacked Bar Graph

Post by rpt » Wed Aug 24, 2016 2:51 pm

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
Amortization Graph.png (60.84 KiB) Viewed 18950 times
[/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.

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Sift 100% Stacked Bar Graph

Post by Christopher » Thu Aug 25, 2016 9:04 am

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;
      }
    }
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

rpt
Newbie
Newbie
Posts: 24
Joined: Wed Aug 09, 2006 12:00 am

Re: Shift 100% Stacked Bar Graph

Post by rpt » Thu Aug 25, 2016 1:14 pm

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.

rpt
Newbie
Newbie
Posts: 24
Joined: Wed Aug 09, 2006 12:00 am

Re: Shift 100% Stacked Bar Graph

Post by rpt » Wed Nov 30, 2016 2:43 pm

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

rpt
Newbie
Newbie
Posts: 24
Joined: Wed Aug 09, 2006 12:00 am

Re: Shift 100% Stacked Bar Graph

Post by rpt » Wed Nov 30, 2016 7:26 pm

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);
            }



        }
    }
}

Attachments
untitled.png
untitled.png (40.1 KiB) Viewed 18831 times

Marc
Site Admin
Site Admin
Posts: 1209
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Re: Shift 100% Stacked Bar Graph

Post by Marc » Thu Dec 01, 2016 3:32 pm

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
BarPolyFill.png (8.86 KiB) Viewed 18815 times
Regards,
Marc Meumann
Steema Support

rpt
Newbie
Newbie
Posts: 24
Joined: Wed Aug 09, 2006 12:00 am

Re: Shift 100% Stacked Bar Graph

Post by rpt » Thu Dec 01, 2016 7:30 pm

Thank You , this worked.

rpt
Newbie
Newbie
Posts: 24
Joined: Wed Aug 09, 2006 12:00 am

Re: Shift 100% Stacked Bar Graph

Post by rpt » Thu Jan 05, 2017 7:19 pm

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
Untitled.png (5.69 KiB) Viewed 18723 times
I want to shift Current to right and increase the Gap in between 2 stacks like you have in above post.

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: Shift 100% Stacked Bar Graph

Post by Christopher » Mon Jan 09, 2017 11:41 am

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?
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

rpt
Newbie
Newbie
Posts: 24
Joined: Wed Aug 09, 2006 12:00 am

Re: Shift 100% Stacked Bar Graph

Post by rpt » Mon Jan 09, 2017 7:37 pm

I am using Ten config file.

Here is the code -

Code: Select all

 StackedBars2.cs
https://github.com/dekajp/TeeChart-for- ... edBars2.cs

Here is the Github repo . https://github.com/dekajp/TeeChart-for- ... ms-samples

Post Reply