Page 1 of 1

Positioning Axes

Posted: Tue Oct 11, 2011 8:26 am
by 15653122
Hi Guys

Using TeeChart for .NET 2010

I'm plotting a line graph and would like to position the bottom and left axes so that they intersect the chart over the centre and form a cross.
teechart.PNG
teechart.PNG (9.55 KiB) Viewed 3846 times
I've achieved what is in the attached image by positioning the axes with the following:

Code: Select all

chart1.Axes.Bottom.PositionUnits = PositionUnits.Percent;
chart1.Axes.Bottom.RelativePosition = 50;
chart1.Axes.Left.PositionUnits = PositionUnits.Percent;
chart1.Axes.Left.RelativePosition = 50;
This is achieving what I want but with the following, undesirable side effects:

- The axes labels are placed with the axes and I can't see a way to position them to the edge of the chart, where they would be if i hadn't repositioned the axes
- The panel has left some space to the left and bottom of the chart, presumably for where the axes were originally positioned. This makes the chart offset and is causing asthetic issues in my application.

I'm wondering, are there any remedies for the issues above? Or more significant, is there a better way to position the axes in the center (at 0)?

I'm thinking that this type of graph isn't too uncommon and I may be missing something.

Thank you

Jamie

Re: Positioning Axes

Posted: Thu Oct 13, 2011 9:16 am
by 10050769
Hello Jaime,

I recommend you take a look in the Tutorial number 4, concretly in section Additional Axes where there are example of how you can position the axes in the center. If you have any problems, please let me know.

I hope will helps.

Thanks,

Re: Positioning Axes

Posted: Mon Oct 17, 2011 10:28 am
by 15653122
Hi Sandra

Thank you for your help. The tutorial did contain what i needed. Specifically this piece of code:

Code: Select all

private void line1_BeforeDrawValues(object sender, Steema.TeeChart.Drawing.Graphics3D g)                      
int posAxis = 0;             
if(tChart1.Axes.Left.Maximum > 0)                              
tChart1.Axes.Left.Draw(g.ChartXCenter - 10,g.ChartXCenter - 20,g.ChartXCenter,true);                 
posAxis = tChart1.Axes.Left.CalcYPosValue(10);                 
tChart1.Axes.Bottom.Draw(posAxis + 10, posAxis + 40, posAxis, true); 
Which effectively redraws the axes at the center, and can then set visible = false on the originals.

This remedies the whitespace and title positioning problems I was having.

Many Thanks

Jamie

Re: Positioning Axes

Posted: Mon Oct 17, 2011 2:55 pm
by 10050769
Hello Jaime,

I suggest that try to do something as next code, where I have used custom axes to achieve as you want:

Code: Select all

        public Form1()
        {
            InitializeComponent();
            InitializeChart();
        }
        Steema.TeeChart.Styles.Line Series1;
        Steema.TeeChart.Axis LeftCustom,BottomCustom;
        private void InitializeChart()
        {
            Random Rnd = new Random();
            LeftCustom = new Steema.TeeChart.Axis(tChart1.Chart);
            BottomCustom = new Steema.TeeChart.Axis(tChart1.Chart);

            tChart1.Axes.Custom.Add(LeftCustom);
            tChart1.Axes.Custom.Add(BottomCustom);

            Series1 = new Line(tChart1.Chart);
            tChart1.Aspect.View3D = false;
            tChart1.Panel.Gradient.Visible = true;

            for (int t = 0; t <= 20; ++t)
            {
                Series1.Add(t, ((Rnd.Next(100)) + 1) - ((Rnd.Next(70)) + 1), Color.Red);
            
            }

            tChart1.Axes.Bottom.Visible = false;
            tChart1.Axes.Left.Visible = false;
            //Define Custom Axis as auxiliary.
            BottomCustom.Horizontal = true;
            Series1.CustomHorizAxis = BottomCustom;
            Series1.CustomVertAxis = LeftCustom;

            tChart1.Panel.MarginBottom = 15;
            tChart1.Panel.MarginLeft = 15;

            BottomCustom.Title.Visible = true;
            BottomCustom.Title.Text = "Bottom";
            LeftCustom.Title.Visible = true;
            LeftCustom.Title.Text = "Left";
            tChart1.Draw();
            Series1.HorizAxis = HorizontalAxis.Bottom;
            Series1.VertAxis = VerticalAxis.Left;

            Series1.BeforeDrawValues += new Steema.TeeChart.PaintChartEventHandler(Series1_BeforeDrawValues);

        }

        void Series1_BeforeDrawValues(object sender, Steema.TeeChart.Drawing.Graphics3D g)
        {
              int posAxis = 0;
              if (tChart1.Axes.Left.Maximum > 0)
              {
                  tChart1.Axes.Left.Draw(g.ChartXCenter - 10, g.ChartXCenter - 20, g.ChartXCenter, true);
                  posAxis = tChart1.Axes.Left.CalcYPosValue(10);   //}              

                  tChart1.Axes.Bottom.Draw(posAxis + 10, posAxis + 40, posAxis, true);
                  
              }
        }
Can you tell us if previous code works as you expected?
I hope will helps.

Thanks,