Problems with multi Axes

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

Problems with multi Axes

Post by Friis » Wed Nov 05, 2014 8:52 pm

Hi,

1) I add 4 series and connect these 4 series to 4 custom axes - 1 series to one custom axes
2) I use a PlaceAxes in order to put the axes in the correct positioning
3) When I first "Activate = false" and then "active =true" using 4 checkBoxes - the axes positioning is completely wrong - eventhough I call PlaceAxes after the "Activate - deactive" series.

the code is below here:

Code: Select all

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Test___Problems_with_Multiple_Axes
{
    public partial class Form1 : Form
    {
        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();
            }

            //========== Serie 1 ==========================

            Steema.TeeChart.Styles.Points Pointsseries = new Steema.TeeChart.Styles.Points(tChart1.Chart);
            this.tChart1.Series.Add(Pointsseries);

            Pointsseries.Title = "Super Axes 1";
            Pointsseries.Color = Color.AliceBlue;

            if ((tChart1.Series.Count % 2) == 0)
            {
                this.tChart1.Axes.Custom.Add(new Steema.TeeChart.Axis(tChart1.Chart));
                this.tChart1.Axes.Custom[this.tChart1.Axes.Custom.Count - 1].OtherSide = false;
            }
            else
            {
                this.tChart1.Axes.Custom.Add(new Steema.TeeChart.Axis(tChart1.Chart));
                this.tChart1.Axes.Custom[this.tChart1.Axes.Custom.Count - 1].OtherSide = true;
            }

            this.tChart1.Axes.Custom[tChart1.Axes.Custom.Count - 1].Title.Text = "Super Axes";
            Pointsseries.CustomVertAxis = this.tChart1.Axes.Custom[tChart1.Axes.Custom.Count - 1];
            this.tChart1.Panel.MarginUnits = Steema.TeeChart.PanelMarginUnits.Pixels;

            Pointsseries.FillSampleValues();

            //========== Serie 2 ==========================

            Steema.TeeChart.Styles.Points Pointsseries2 = new Steema.TeeChart.Styles.Points(tChart1.Chart);
            this.tChart1.Series.Add(Pointsseries2);

            Pointsseries2.Title = "Super Axes 2";
            Pointsseries2.Color = Color.LimeGreen;

            if ((tChart1.Series.Count % 2) == 0)
            {
                this.tChart1.Axes.Custom.Add(new Steema.TeeChart.Axis(tChart1.Chart));
                this.tChart1.Axes.Custom[this.tChart1.Axes.Custom.Count - 1].OtherSide = false;
            }
            else
            {
                this.tChart1.Axes.Custom.Add(new Steema.TeeChart.Axis(tChart1.Chart));
                this.tChart1.Axes.Custom[this.tChart1.Axes.Custom.Count - 1].OtherSide = true;
            }

            this.tChart1.Axes.Custom[tChart1.Axes.Custom.Count - 1].Title.Text = "Super Axes 2";
            Pointsseries2.CustomVertAxis = this.tChart1.Axes.Custom[tChart1.Axes.Custom.Count - 1];
            this.tChart1.Panel.MarginUnits = Steema.TeeChart.PanelMarginUnits.Pixels;

            Pointsseries2.FillSampleValues();

            //========== Serie 3 ==========================

            Steema.TeeChart.Styles.Points Pointsseries3 = new Steema.TeeChart.Styles.Points(tChart1.Chart);
            this.tChart1.Series.Add(Pointsseries3);

            Pointsseries3.Title = "Super Axes 3";
            Pointsseries3.Color = Color.Blue;

            if ((tChart1.Series.Count % 2) == 0)
            {
                this.tChart1.Axes.Custom.Add(new Steema.TeeChart.Axis(tChart1.Chart));
                this.tChart1.Axes.Custom[this.tChart1.Axes.Custom.Count - 1].OtherSide = false;
            }
            else
            {
                this.tChart1.Axes.Custom.Add(new Steema.TeeChart.Axis(tChart1.Chart));
                this.tChart1.Axes.Custom[this.tChart1.Axes.Custom.Count - 1].OtherSide = true;
            }

            this.tChart1.Axes.Custom[tChart1.Axes.Custom.Count - 1].Title.Text = "Super Axes 3";
            Pointsseries3.CustomVertAxis = this.tChart1.Axes.Custom[tChart1.Axes.Custom.Count - 1];
            this.tChart1.Panel.MarginUnits = Steema.TeeChart.PanelMarginUnits.Pixels;

            Pointsseries3.FillSampleValues();

            //========== Serie 4 ==========================

            Steema.TeeChart.Styles.Points Pointsseries4 = new Steema.TeeChart.Styles.Points(tChart1.Chart);
            this.tChart1.Series.Add(Pointsseries4);

            Pointsseries4.Title = "Super Axes 4";
            Pointsseries4.Color = Color.Red;

            if ((tChart1.Series.Count % 2) == 0)
            {
                this.tChart1.Axes.Custom.Add(new Steema.TeeChart.Axis(tChart1.Chart));
                this.tChart1.Axes.Custom[this.tChart1.Axes.Custom.Count - 1].OtherSide = false;
            }
            else
            {
                this.tChart1.Axes.Custom.Add(new Steema.TeeChart.Axis(tChart1.Chart));
                this.tChart1.Axes.Custom[this.tChart1.Axes.Custom.Count - 1].OtherSide = true;
            }

            this.tChart1.Axes.Custom[tChart1.Axes.Custom.Count - 1].Title.Text = "Super Axes 4";
            Pointsseries4.CustomVertAxis = this.tChart1.Axes.Custom[tChart1.Axes.Custom.Count - 1];
            this.tChart1.Panel.MarginUnits = Steema.TeeChart.PanelMarginUnits.Pixels;

            Pointsseries4.FillSampleValues();

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

            PlaceAxes(0, 0, 0, 0, 0);

        }

        private void saveImageToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // set a default file name
            saveFileDialog1.FileName = "unknown.JPEG";
            // set filters - this can be done in properties as well
            saveFileDialog1.Filter = "JPEG file (*.JPEG)|*.JPEG";

            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                tChart1.Export.Image.JPEG.Save(@saveFileDialog1.FileName);
            }
        }

        private void PlaceAxes(int nSeries, int NextXLeft, int NextXRight, int MargLeft, int MargRight)
        {
            const int extraPos = 50;
            const int extraMargin = 105;
            //Variable 
            int MaxLabelsWidth;
            int lenghtTicks;
            int extraSpaceBetweenTitleAndLabels;
            if (tChart1[nSeries].Active)
            {
                MaxLabelsWidth = tChart1.Axes.Custom[nSeries].MaxLabelsWidth();
                lenghtTicks = tChart1.Axes.Custom[nSeries].Ticks.Length;
                extraSpaceBetweenTitleAndLabels = (tChart1.Axes.Custom[nSeries].Title.Width);//- tChart1.Axes.Custom[nSeries].MaxLabelsWidth());
                if (tChart1.Axes.Custom[nSeries].OtherSide)
                {
                    tChart1.Axes.Custom[nSeries].RelativePosition = NextXRight;
                    NextXRight = NextXRight - (MaxLabelsWidth + lenghtTicks + extraSpaceBetweenTitleAndLabels + extraPos);
                    MargRight = MargRight + extraMargin;
                }

                else
                {
                    tChart1.Axes.Custom[nSeries].RelativePosition = NextXLeft;
                    NextXLeft = NextXLeft - (MaxLabelsWidth + lenghtTicks + extraSpaceBetweenTitleAndLabels + extraPos);
                    MargLeft = MargLeft + extraMargin;
                }

                tChart1.Panel.MarginLeft = MargLeft;
                tChart1.Panel.MarginRight = MargRight;

                nSeries++;

                if (nSeries <= tChart1.Series.Count - 1)
                
                    PlaceAxes(nSeries, NextXLeft, NextXRight, MargLeft, MargRight);
                
            }
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            tChart1[0].Active = checkBox1.Checked;
            PlaceAxes(0, 0, 0, 0, 0);
        }

        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {
            tChart1[1].Active = checkBox2.Checked;
            PlaceAxes(0, 0, 0, 0, 0);
        }

        private void checkBox3_CheckedChanged(object sender, EventArgs e)
        {
            tChart1[2].Active = checkBox3.Checked;
            PlaceAxes(0, 0, 0, 0, 0);
        }

        private void checkBox4_CheckedChanged(object sender, EventArgs e)
        {
            tChart1[3].Active = checkBox4.Checked;
            PlaceAxes(0, 0, 0, 0, 0);
        }
    }
}


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

Re: Problems with multi Axes

Post by Friis » Thu Nov 06, 2014 7:13 am

Hi,

I have added two images illustrating the problems with the axes.

Kind regards - HH Friis
Attachments
MultipleAxes_WRONG.JPEG
MultipleAxes_WRONG.JPEG (296.85 KiB) Viewed 14393 times
MultipleAxes_OK.JPEG
MultipleAxes_OK.JPEG (294.29 KiB) Viewed 14383 times

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

Re: Problems with multi Axes

Post by Christopher » Thu Nov 06, 2014 10:10 am

Hello!

Your code needs some more work, but using only checkBox1 I think it will function as expected with the following two changes:

1)

Code: Select all

      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;
        tChart1.Axes.Custom[i].FixedLabelSize = false;
      }

      tChart1.Draw(); //<- here

      PlaceAxes(0, 0, 0, 0, 0);

    }
2)

Code: Select all

      if (tChart1[nSeries].Active)
      {
        MaxLabelsWidth = tChart1.Axes.Custom[nSeries].MaxLabelsWidth();
        lenghtTicks = tChart1.Axes.Custom[nSeries].Ticks.Length;
        extraSpaceBetweenTitleAndLabels = 0; //(tChart1.Axes.Custom[nSeries].Title.Width);//<- here
        if (tChart1.Axes.Custom[nSeries].OtherSide)
        {
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: Problems with multi Axes

Post by Friis » Thu Nov 06, 2014 10:40 am

Hi,

Thnx for helping me out ;-)

it works, however, I had to change the checkBoxes onclickevent to:

Code: Select all

            tChart1[3].Visible = checkBox4.Checked;
            tChart1.Axes.Custom[3].Visible = tChart1[3].Visible;
            tChart1.Draw(); //<- here
            PlaceAxes(0, 0, 0, 0, 0);

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

Re: Problems with multi Axes

Post by Friis » Thu Nov 06, 2014 12:15 pm

Hi Christopher,

I'm sorry but it still doesn't work

1) Try to start with all 4 series active = all 4 chckboxes checked.
2) Then uncheck first checkbox4, then uncheck checkbox3, then uncheck checkbox2 and finally uncheck checkbox1 - (series4.Active = false; then series3.Active = false; then series2.active=false, ect...)
The order in which you unchck is very important!!
3) Activate series 3 / check ckeckbox3
3) as you can see the axes positioning is still incorrect...??

Code: Select all

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Test___Problems_with_Multiple_Axes
{
    public partial class Form1 : Form
    {
        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();
            }

            //========== Serie 1 ==========================

            Steema.TeeChart.Styles.Points Pointsseries = new Steema.TeeChart.Styles.Points(tChart1.Chart);
            this.tChart1.Series.Add(Pointsseries);

            Pointsseries.Title = "Super Axes 1";
            Pointsseries.Color = Color.AliceBlue;

            if ((tChart1.Series.Count % 2) == 0)
            {
                this.tChart1.Axes.Custom.Add(new Steema.TeeChart.Axis(tChart1.Chart));
                this.tChart1.Axes.Custom[this.tChart1.Axes.Custom.Count - 1].OtherSide = false;
            }
            else
            {
                this.tChart1.Axes.Custom.Add(new Steema.TeeChart.Axis(tChart1.Chart));
                this.tChart1.Axes.Custom[this.tChart1.Axes.Custom.Count - 1].OtherSide = true;
            }

            this.tChart1.Axes.Custom[tChart1.Axes.Custom.Count - 1].Title.Text = "Super Axes";
            Pointsseries.CustomVertAxis = this.tChart1.Axes.Custom[tChart1.Axes.Custom.Count - 1];
            this.tChart1.Panel.MarginUnits = Steema.TeeChart.PanelMarginUnits.Pixels;

            Pointsseries.FillSampleValues();

            //========== Serie 2 ==========================

            Steema.TeeChart.Styles.Points Pointsseries2 = new Steema.TeeChart.Styles.Points(tChart1.Chart);
            this.tChart1.Series.Add(Pointsseries2);

            Pointsseries2.Title = "Super Axes 2";
            Pointsseries2.Color = Color.LimeGreen;

            if ((tChart1.Series.Count % 2) == 0)
            {
                this.tChart1.Axes.Custom.Add(new Steema.TeeChart.Axis(tChart1.Chart));
                this.tChart1.Axes.Custom[this.tChart1.Axes.Custom.Count - 1].OtherSide = false;
            }
            else
            {
                this.tChart1.Axes.Custom.Add(new Steema.TeeChart.Axis(tChart1.Chart));
                this.tChart1.Axes.Custom[this.tChart1.Axes.Custom.Count - 1].OtherSide = true;
            }

            this.tChart1.Axes.Custom[tChart1.Axes.Custom.Count - 1].Title.Text = "Super Axes 2";
            Pointsseries2.CustomVertAxis = this.tChart1.Axes.Custom[tChart1.Axes.Custom.Count - 1];
            this.tChart1.Panel.MarginUnits = Steema.TeeChart.PanelMarginUnits.Pixels;

            Pointsseries2.FillSampleValues();

            //========== Serie 3 ==========================

            Steema.TeeChart.Styles.Points Pointsseries3 = new Steema.TeeChart.Styles.Points(tChart1.Chart);
            this.tChart1.Series.Add(Pointsseries3);

            Pointsseries3.Title = "Super Axes 3";
            Pointsseries3.Color = Color.Blue;

            if ((tChart1.Series.Count % 2) == 0)
            {
                this.tChart1.Axes.Custom.Add(new Steema.TeeChart.Axis(tChart1.Chart));
                this.tChart1.Axes.Custom[this.tChart1.Axes.Custom.Count - 1].OtherSide = false;
            }
            else
            {
                this.tChart1.Axes.Custom.Add(new Steema.TeeChart.Axis(tChart1.Chart));
                this.tChart1.Axes.Custom[this.tChart1.Axes.Custom.Count - 1].OtherSide = true;
            }

            this.tChart1.Axes.Custom[tChart1.Axes.Custom.Count - 1].Title.Text = "Super Axes 3";
            Pointsseries3.CustomVertAxis = this.tChart1.Axes.Custom[tChart1.Axes.Custom.Count - 1];
            this.tChart1.Panel.MarginUnits = Steema.TeeChart.PanelMarginUnits.Pixels;

            Pointsseries3.FillSampleValues();

            //========== Serie 4 ==========================

            Steema.TeeChart.Styles.Points Pointsseries4 = new Steema.TeeChart.Styles.Points(tChart1.Chart);
            this.tChart1.Series.Add(Pointsseries4);

            Pointsseries4.Title = "Super Axes 4";
            Pointsseries4.Color = Color.Red;

            if ((tChart1.Series.Count % 2) == 0)
            {
                this.tChart1.Axes.Custom.Add(new Steema.TeeChart.Axis(tChart1.Chart));
                this.tChart1.Axes.Custom[this.tChart1.Axes.Custom.Count - 1].OtherSide = false;
            }
            else
            {
                this.tChart1.Axes.Custom.Add(new Steema.TeeChart.Axis(tChart1.Chart));
                this.tChart1.Axes.Custom[this.tChart1.Axes.Custom.Count - 1].OtherSide = true;
            }

            this.tChart1.Axes.Custom[tChart1.Axes.Custom.Count - 1].Title.Text = "Super Axes 4";
            Pointsseries4.CustomVertAxis = this.tChart1.Axes.Custom[tChart1.Axes.Custom.Count - 1];
            this.tChart1.Panel.MarginUnits = Steema.TeeChart.PanelMarginUnits.Pixels;

            Pointsseries4.FillSampleValues();

            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;
                tChart1.Axes.Custom[i].FixedLabelSize = false;
            }
            
            tChart1.Draw(); //<- here

            PlaceAxes(0, 0, 0, 0, 0);

        }

        private void saveImageToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // set a default file name
            saveFileDialog1.FileName = "unknown.JPEG";
            // set filters - this can be done in properties as well
            saveFileDialog1.Filter = "JPEG file (*.JPEG)|*.JPEG";

            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                tChart1.Export.Image.JPEG.Save(@saveFileDialog1.FileName);
            }
        }

        private void PlaceAxes(int nSeries, int NextXLeft, int NextXRight, int MargLeft, int MargRight)
        {
            const int extraPos = 50;
            const int extraMargin = 105;
            //Variable 
            int MaxLabelsWidth;
            int lenghtTicks;
            int extraSpaceBetweenTitleAndLabels;
            if (tChart1[nSeries].Active)
            {
                MaxLabelsWidth = tChart1.Axes.Custom[nSeries].MaxLabelsWidth();
                lenghtTicks = tChart1.Axes.Custom[nSeries].Ticks.Length;
                extraSpaceBetweenTitleAndLabels = 0; //(tChart1.Axes.Custom[nSeries].Title.Width);//<- here
                //extraSpaceBetweenTitleAndLabels = (tChart1.Axes.Custom[nSeries].Title.Width);//- tChart1.Axes.Custom[nSeries].MaxLabelsWidth());
                if (tChart1.Axes.Custom[nSeries].OtherSide)
                {
                    tChart1.Axes.Custom[nSeries].RelativePosition = NextXRight;
                    NextXRight = NextXRight - (MaxLabelsWidth + lenghtTicks + extraSpaceBetweenTitleAndLabels + extraPos);
                    MargRight = MargRight + extraMargin;
                }

                else
                {
                    tChart1.Axes.Custom[nSeries].RelativePosition = NextXLeft;
                    NextXLeft = NextXLeft - (MaxLabelsWidth + lenghtTicks + extraSpaceBetweenTitleAndLabels + extraPos);
                    MargLeft = MargLeft + extraMargin;
                }

                tChart1.Panel.MarginLeft = MargLeft;
                tChart1.Panel.MarginRight = MargRight;

                nSeries++;

                if (nSeries <= tChart1.Series.Count - 1)
                
                    PlaceAxes(nSeries, NextXLeft, NextXRight, MargLeft, MargRight);
                
            }
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            tChart1[0].Active = checkBox1.Checked;
            tChart1.Axes.Custom[0].Visible = tChart1[0].Active;
            tChart1.Draw(); //<- here
            PlaceAxes(0, 0, 0, 0, 0);
        }

        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {
            tChart1[1].Active = checkBox2.Checked;
            tChart1.Axes.Custom[1].Visible = tChart1[1].Active;
            tChart1.Draw(); //<- here
            PlaceAxes(0, 0, 0, 0, 0);
        }

        private void checkBox3_CheckedChanged(object sender, EventArgs e)
        {
            tChart1[2].Active = checkBox3.Checked;
            tChart1.Axes.Custom[2].Visible = tChart1[2].Active;
            tChart1.Draw(); //<- here
            PlaceAxes(0, 0, 0, 0, 0);
        }

        private void checkBox4_CheckedChanged(object sender, EventArgs e)
        {
            tChart1[3].Active = checkBox4.Checked;
            tChart1.Axes.Custom[3].Visible = tChart1[3].Active;
            tChart1.Draw(); //<- here
            PlaceAxes(0, 0, 0, 0, 0);
        }
    }
}


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

Re: Problems with multi Axes

Post by Christopher » Thu Nov 06, 2014 2:58 pm

Hello,

To resolve the issue you speak of, all that is necessary is the following change:

Code: Select all

    private void checkBox3_CheckedChanged(object sender, EventArgs e)
    {
      tChart1[2].Active = checkBox3.Checked;
      tChart1.Axes.Custom[2].Visible = tChart1[2].Active;
      tChart1.Draw(); //<- here
      PlaceAxes(2, 0, 0, 0, 0); //<- here
    }
As I say, I think your code needs a little more work before being robust.
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: Problems with multi Axes

Post by Friis » Thu Nov 06, 2014 3:10 pm

Hi,

I have tried to change it in accordance with your instructions, see code below

1) Start with all series active=true
2) then try to inactive series 3 and re-activate the series (uncheck checkbox3, then recheck checkbox 3)

That makes the axes overlap...??

Code: Select all


        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            tChart1[0].Visible = checkBox1.Checked;
            tChart1.Axes.Custom[0].Visible = tChart1[0].Visible;
            tChart1.Draw(); //<- here
            PlaceAxes(0, 0, 0, 0, 0);
        }

        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {
            tChart1[1].Visible = checkBox2.Checked;
            tChart1.Axes.Custom[1].Visible = tChart1[1].Visible;
            tChart1.Draw(); //<- here
            PlaceAxes(1, 0, 0, 0, 0);
        }

        private void checkBox3_CheckedChanged(object sender, EventArgs e)
        {
            tChart1[2].Visible = checkBox3.Checked;
            tChart1.Axes.Custom[2].Visible = tChart1[2].Visible;
            tChart1.Draw(); //<- here
            PlaceAxes(2, 0, 0, 0, 0);
        }

        private void checkBox4_CheckedChanged(object sender, EventArgs e)
        {
            tChart1[3].Visible = checkBox4.Checked;
            tChart1.Axes.Custom[3].Visible = tChart1[3].Visible;
            tChart1.Draw(); //<- here
            PlaceAxes(3, 0, 0, 0, 0);
        }

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

Re: Problems with multi Axes

Post by Christopher » Thu Nov 06, 2014 3:24 pm

Friis wrote:Hi
Try:

Code: Select all

    private void PlaceAxes(int NextXLeft, int NextXRight, int MargLeft, int MargRight)
    {
      const int extraPos = 50;
      const int extraMargin = 105;
      //Variable 
      int MaxLabelsWidth;
      int lenghtTicks;
      int extraSpaceBetweenTitleAndLabels;

      for (int nSeries = 0; nSeries < tChart1.Series.Count; nSeries++)
      {
        if (tChart1[nSeries].Active)
        {
          MaxLabelsWidth = tChart1.Axes.Custom[nSeries].MaxLabelsWidth();
          lenghtTicks = tChart1.Axes.Custom[nSeries].Ticks.Length;
          extraSpaceBetweenTitleAndLabels = 0; //(tChart1.Axes.Custom[nSeries].Title.Width);//<- here
          //extraSpaceBetweenTitleAndLabels = (tChart1.Axes.Custom[nSeries].Title.Width);//- tChart1.Axes.Custom[nSeries].MaxLabelsWidth());
          if (tChart1.Axes.Custom[nSeries].OtherSide)
          {
            tChart1.Axes.Custom[nSeries].RelativePosition = NextXRight;
            NextXRight = NextXRight - (MaxLabelsWidth + lenghtTicks + extraSpaceBetweenTitleAndLabels + extraPos);
            MargRight = MargRight + extraMargin;
          }

          else
          {
            tChart1.Axes.Custom[nSeries].RelativePosition = NextXLeft;
            NextXLeft = NextXLeft - (MaxLabelsWidth + lenghtTicks + extraSpaceBetweenTitleAndLabels + extraPos);
            MargLeft = MargLeft + extraMargin;
          }

          tChart1.Panel.MarginLeft = MargLeft;
          tChart1.Panel.MarginRight = MargRight;
        }
      }
    }
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: Problems with multi Axes

Post by Friis » Fri Nov 07, 2014 7:02 am

Thank you for helping me ;-)

It works really well now ;-)

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

Re: Problems with multi Axes

Post by Christopher » Fri Nov 07, 2014 8:35 am

Friis wrote:Thank you for helping me ;-)
You are very welcome :)

Please do not hesitate to contact us with any further TeeChart issues.
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

Post Reply