positioning of CustomAxes in TChart

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Friis
Newbie
Newbie
Posts: 26
Joined: Thu Oct 16, 2014 12:00 am

positioning of CustomAxes in TChart

Post by Friis » Wed Oct 22, 2014 3:12 pm

Hi,

When adding custom axes in Tchart, the alignment and positioning of the axis and particular the titles for these extra customAxes seems to be a little "off."

In those cases, for delphi, you have made a code that takes care of this, see below:

Should a similar code be used for .NET?

Code: Select all


procedure TFMainForm.PlaceAxes(nSeries: Integer=0; NextXLeft: Integer=0; NextXRight: Integer=0; MargLeft: Integer=10; MargRight: Integer=10);
const extraPos = 62;
const extraMargin = 100;
begin

AfBildningChart1.MarginLeft := 0;
AfBildningChart1.MarginRight := 0;

  if (AfBildningChart1.CustomAxes.Count > 0) then
    begin
      if AfBildningChart1.CustomAxes.Items[nSeries].OtherSide and AfBildningChart1.CustomAxes.Items[nSeries].Visible then
        begin
          AfBildningChart1.CustomAxes.Items[nSeries].PositionPercent := NextXRight;
          NextXRight := NextXRight - AfBildningChart1.CustomAxes.Items[nSeries].MaxLabelsWidth - AfBildningChart1.CustomAxes.Items[nSeries].TickLength - extraPos;
          MargRight := MargRight + extraMargin;
        end
      else if AfBildningChart1.CustomAxes.Items[nSeries].Visible then
        begin
          AfBildningChart1.CustomAxes.Items[nSeries].PositionPercent := NextXLeft;
          NextXLeft := NextXLeft - AfBildningChart1.CustomAxes.Items[nSeries].MaxLabelsWidth - AfBildningChart1.CustomAxes.Items[nSeries].TickLength - extraPos;
          MargLeft := MargLeft + extraMargin;
        end;
    end;

  AfBildningChart1.MarginLeft := MargLeft;
  AfBildningChart1.MarginRight := MargRight;
  AfBildningChart1.MarginBottom := 20;

  nSeries := nSeries + 1;

  if (nSeries < AfBildningChart1.CustomAxes.Count) then
  begin
    PlaceAxes(nSeries, NextXLeft, NextXRight, MargLeft, MargRight);
  end;

//  showmessage('MargLeft' + inttostr(MargLeft) + ' MargRight=' + inttostr(MargRight));
end;

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

Re: positioning of CustomAxes in TChart

Post by Christopher » Thu Oct 23, 2014 8:52 am

Hello,
Friis wrote: Should a similar code be used for .NET?
Yes, I think so.
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

Friis
Newbie
Newbie
Posts: 26
Joined: Thu Oct 16, 2014 12:00 am

Re: positioning of CustomAxes in TChart

Post by Friis » Sun Oct 26, 2014 7:49 pm

Hi,

I have tried to make the following test case. As you can see in the example, the right axis "disappear" and cannot be seen - nor can the title be seen.

Further below I have tried to translate the code "PlaceAxes" from Delphi to .NET - I was given this code from Narcis wrt. Delphi and placing axes. I have not been able to translate and the debugger gives many errors - I need you help to translate this code in order for me to solve the problem with the custom axes

Code: Select all

        public Form1()
        {
            InitializeComponent();

            tChart1.Series.Clear();
            tChart1.Series.RemoveAllSeries();
            tChart1.Dock = DockStyle.Fill;
            tChart1.BackColor = Color.White;
            tChart1.Walls.Back.Gradient.Visible = false;
            tChart1.Walls.Back.Color = Color.White;
            tChart1.Walls.Bottom.Gradient.Visible = false;
            tChart1.Walls.Bottom.Color = Color.White;
            tChart1.Panel.Gradient.Visible = false;
            tChart1.Panel.Color = Color.White;
            tChart1.Aspect.View3D = false;
            tChart1.Panel.Bevel.Outer = Steema.TeeChart.Drawing.BevelStyles.None;
            tChart1.Axes.Left.Automatic = true;
            tChart1.Axes.Bottom.Automatic = true;
            tChart1.Axes.Left.Title.Caption = "";
            tChart1.Axes.Bottom.Title.Caption = "";
            tChart1.Header.Text = "";
            tChart1.Legend.Visible = false;
            tChart1.Legend.Shadow.Visible = false;
            tChart1.Legend.Font.Size = 14;
            tChart1.Legend.Symbol.Width = 50;
            tChart1.Legend.Symbol.Squared = true;


            if (tChart1.Axes.Custom.Count > 0)
            {
                tChart1.Axes.Custom.Clear();
            }

            Steema.TeeChart.Styles.Points Pointsseries = new Steema.TeeChart.Styles.Points(tChart1.Chart);
            this.tChart1.Series.Add(Pointsseries);
            
            Pointsseries.Add(10, 0.1, "", Color.Red);
            Pointsseries.Add(20, 0.5, "", Color.Red);
            Pointsseries.Add(30, 0.25, "", Color.Red);
            Pointsseries.Add(40, 0.01, "", Color.Red);
            Pointsseries.Add(50, 0.7, "", Color.Red);
            
            Steema.TeeChart.Styles.Points Pointsseries2 = new Steema.TeeChart.Styles.Points(tChart1.Chart);
            this.tChart1.Series.Add(Pointsseries2);

            this.tChart1.Axes.Custom.Add(this.tChart1.Axes.Right);
            this.tChart1.Axes.Custom[0].Title.Text = "jubii";
            Pointsseries2.CustomVertAxis = this.tChart1.Axes.Custom[0];
            this.tChart1.Panel.MarginUnits = Steema.TeeChart.PanelMarginUnits.Pixels;

            Pointsseries.Add(10, 1, "", Color.Blue);
            Pointsseries.Add(20, 5, "", Color.Blue);
            Pointsseries.Add(30, 2.5, "", Color.Blue);
            Pointsseries.Add(40, 0.1, "", Color.Blue);
            Pointsseries.Add(50, 7, "", Color.Blue);

            for (int i=0;i<tChart1.Axes.Custom.Count;i++)
            {
                tChart1.Axes.Custom[i].Title.Angle = 90;
                tChart1.Axes.Custom[i].PositionUnits = Steema.TeeChart.PositionUnits.Pixels;
                tChart1.Axes.Custom[i].Grid.Visible = false;
            }

        }

Below here is the PlaceAxes code:

Code: Select all

        private void PlaceAxes()
        {
            const double extraPos = 62;
            const double extraMargin = 100;
            double NextXLeft = 0;
            double NextXRight = 0;
            double MargLeft = 10;
            double MargRight = 10;
            int i = 0;

            tChart1.Margin.Left = 0;
            tChart1.Margin.Right = 0;

            if (tChart1.Axes.Custom.Count > 0)
            {
                if (tChart1.Axes.Custom[i].OtherSide)
                {
                    tChart1.Axes.Custom[i].Position = NextXRight;
                    NextXRight = NextXRight -
                        Convert.ToDouble(tChart1.Axes.Custom[i].MaxLabelsWidth) -
                        Convert.ToDouble(tChart1.Axes.Custom[i].Ticks.Length) - extraPos;
                    MargRight = MargRight + extraMargin;
                }
                else
                {
                    tChart1.Axes.Custom[i].Position = NextXLeft;
                    NextXLeft = NextXLeft -
                        Convert.ToDouble(tChart1.Axes.Custom[i].MaxLabelsWidth) -
                        Convert.ToDouble(tChart1.Axes.Custom[i].Ticks.Length) - extraPos;
                    MargLeft = MargLeft + extraMargin;
                }

            }

            tChart1.Margin.Left = Convert.ToInt16(MargLeft);
            tChart1.Margin.Right = Convert.ToInt16(MargRight);
            tChart1.Margin.Bottom = 20;
        }


Friis
Newbie
Newbie
Posts: 26
Joined: Thu Oct 16, 2014 12:00 am

Re: positioning of CustomAxes in TChart

Post by Friis » Sun Oct 26, 2014 7:59 pm

I have added a photo of the graph here where you can see the incorrect positioning of the right axes ;-)
Attachments
unknown.JPEG
unknown.JPEG (258.19 KiB) Viewed 9884 times

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

Re: positioning of CustomAxes in TChart

Post by Christopher » Mon Oct 27, 2014 9:16 am

Hello,
Friis wrote:Further below I have tried to translate the code "PlaceAxes" from Delphi to .NET - I was given this code from Narcis wrt. Delphi and placing axes. I have not been able to translate and the debugger gives many errors - I need you help to translate this code in order for me to solve the problem with the custom axes
There's a .NET translation of the code here.
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

Friis
Newbie
Newbie
Posts: 26
Joined: Thu Oct 16, 2014 12:00 am

Re: positioning of CustomAxes in TChart

Post by Friis » Mon Oct 27, 2014 9:35 am

Thanks - that solved the problem ;-)

Post Reply