Dates Range on the bottom axis - properties

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
qcrnd
Advanced
Posts: 214
Joined: Mon Sep 04, 2006 12:00 am

Re: Dates Range on the bottom axis - properties

Post by qcrnd » Mon Mar 01, 2010 10:06 am

Hi

Can you please summarize the code that I should use?
Since there is a lot of code there of ( changing the axis with angle 90 or 0 and definition of chart) that is not relevant to me.

Thanks

qcrnd
Advanced
Posts: 214
Joined: Mon Sep 04, 2006 12:00 am

Re: Dates Range on the bottom axis - properties

Post by qcrnd » Sun Mar 07, 2010 1:10 pm

Hi ,

I tried to understand the code in the linked thread , but I don't think that it is the same problem.
Can you please assist ? Did you download the example project that I send you?

Thanks.

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Dates Range on the bottom axis - properties

Post by Sandra » Mon Mar 08, 2010 10:32 am

Hello gcrnd,

I understood that your problem basically is that labels overlap in the bottom axis and this cause when the chart is done smaller, labels are not seen clearly. Please you can say it is your problem?

If it is your problem, please tell us what problems you can find a solution to the thread that we will propose.

If it isn't your problem, please, can you what explain is your problem exactly, because we can reproduce here and help you.



Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

qcrnd
Advanced
Posts: 214
Joined: Mon Sep 04, 2006 12:00 am

Re: Dates Range on the bottom axis - properties

Post by qcrnd » Sun Mar 14, 2010 2:09 pm

Hi

I try to understand and to use the code in the tread, but it is not working form me.
I need some method like "on draw" that will calculate all over again where the label are draw and to decide if to show the label or not.
Can you please see the example that I send you in order to reproduce the problem and tell how to solve it.
This behavior already exist in tee chart the only thing that I want is to add the start and the end date.
The perfect solution for me is , if I can use the automatic generated labels by tee chart and to add in addition the first and the last date.

Can you pleas show me how to do it?

Thanks

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Dates Range on the bottom axis - properties

Post by Sandra » Tue Mar 16, 2010 1:24 pm

Hello gcrnd,

I made two examples that I think you can use in your application. The first example is using GetNextAxisLabel Event and second using GetAxisLabel Event

First example using GetNextAxisLabel:

Code: Select all

        public Form1()
        {
            InitializeComponent();
            InitializeChart();
        }
        private Steema.TeeChart.Styles.Bar bar1;
        private bool first = true;
        double newValue;
        private void InitializeChart()
        {
            tChart1.Aspect.View3D = false;
            tChart1.Dock = DockStyle.Fill;
            bar1 = new Steema.TeeChart.Styles.Bar(tChart1.Chart);
            bar1.Marks.Visible = false;
            Random rnd = new Random();
            bar1.XValues.DateTime = true;
            tChart1.Panel.MarginBottom = 20;
            for (int i = 0; i < 50; ++i)
            {
                bar1.Add(DateTime.Now.AddDays(i), rnd.Next(100), Color.Red);
            }
            tChart1.Axes.Bottom.Labels.Angle = 90;
            tChart1.Axes.Bottom.Increment = Steema.TeeChart.Utils.GetDateTimeStep(Steema.TeeChart.DateTimeSteps.TwoDays);
            tChart1.GetNextAxisLabel += new Steema.TeeChart.GetNextAxisLabelEventHandler(tChart1_GetNextAxisLabel);
        }
    
        void tChart1_GetNextAxisLabel(object sender, Steema.TeeChart.GetNextAxisLabelEventArgs e)
        {
            double seriesIncrement = tChart1[0].XValues[1] - tChart1[0].XValues[0];
            if ((sender as Steema.TeeChart.Axis).Equals(tChart1.Axes.Bottom))
            {
                e.Stop = false;

                if (first)
                {
                    newValue = e.LabelValue;
                    first = false;
                }
                else
                {
                    newValue += seriesIncrement;           
                }

                if (e.LabelIndex == 0)
                {
                   
                   e.LabelValue = tChart1.Axes.Bottom.CalcPosPoint(tChart1.Axes.Left.Position);
                   DateTime.FromOADate(e.LabelValue).ToShortDateString();
                  
                }
                else
                {
                    if (e.LabelIndex == tChart1[0].Count)
                    {
                        e.LabelValue = tChart1.Axes.Bottom.CalcPosPoint(tChart1.Axes.Bottom.IEndPos);
                        DateTime.FromOADate(e.LabelValue).ToShortDateString();
                    
                    }
                    else
                    {
                        if (e.LabelIndex < tChart1[0].Count)
                        {
                            e.LabelValue = newValue;
                            DateTime.FromOADate(e.LabelValue).ToShortDateString();

                        }
                        else
                        {
                            e.Stop = true;
                            first = true;
                        }
                    }
                }
            }
        }

Second example with GetAxisLabel Event:

Code: Select all

        public Form1()
        {
            InitializeComponent();
            InitializeChart();
        }
        private Steema.TeeChart.Styles.Bar bar1;
        private bool first = true;
        double newValue;
        private void InitializeChart()
        {
            tChart1.Aspect.View3D = false;
            tChart1.Dock = DockStyle.Fill;

            bar1 = new Steema.TeeChart.Styles.Bar(tChart1.Chart);
            bar1.Marks.Visible = false;
            Random rnd = new Random();
            bar1.XValues.DateTime = true;
            tChart1.Panel.MarginBottom = 20;
            for (int i = 0; i < 50; ++i)
            {
                bar1.Add(DateTime.Now.AddDays(i), rnd.Next(100), Color.Red);
            }
            tChart1.Axes.Bottom.Labels.Angle = 90;
            tChart1.Axes.Bottom.Labels.Style = Steema.TeeChart.AxisLabelStyle.Mark;
            tChart1.GetAxisLabel += new Steema.TeeChart.GetAxisLabelEventHandler(tChart1_GetAxisLabel);
        }
     void tChart1_GetAxisLabel(object sender, Steema.TeeChart.GetAxisLabelEventArgs e)
        {
            if (sender.Equals(tChart1.Axes.Bottom))
            {
                if (e.ValueIndex != -1)
                {
                    if (e.ValueIndex == bar1.Count - 2)
                    {
                        e.LabelText = DateTime.FromOADate(e.Series.XValues[e.ValueIndex + 1]).ToShortDateString();
                    }
                    else
                    {
                        e.LabelText = DateTime.FromOADate(e.Series.XValues[e.ValueIndex]).ToShortDateString();
                    }
                }

            }        
I hope will helps.

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

qcrnd
Advanced
Posts: 214
Joined: Mon Sep 04, 2006 12:00 am

Re: Dates Range on the bottom axis - properties

Post by qcrnd » Thu Mar 18, 2010 12:10 pm

Hi Sandra,

I think you don't understand the problem that I have, since I tried to use the code that you send , and in the both of them have the problems that I already told you.
Example 1 : draw all the dates , but when the window is too small the dates are drown on top of each other.( see I marked it in blue).
ex1.JPG
ex1.JPG (37.4 KiB) Viewed 19425 times
Example 2 :The dates look ok, but the first and the last date in the range does not appear all the time . (I marked in blue the missing date)
Ex 2.JPG
Ex 2.JPG (89.23 KiB) Viewed 19415 times
I want to marge between them - I want to see clearly the dates as in ex2 , but I want the first and the last label always to be shown.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Dates Range on the bottom axis - properties

Post by Narcís » Thu Mar 18, 2010 1:28 pm

Hi qcrnd,

We have slightly modified the 1st example Sandra posted in her last thread. Now GetNextAxisLabel event takes into account bottom axis increment. This works fine for us here using latest TeeChart for .NET v2009 release available at the client area. Which is the exact TeeChart version you are using? Can you please check if it works fine at your end? You can set bottom axis increment to fit your needs.

Code: Select all

		public Form1()
		{
			InitializeComponent();
			InitializeChart();
		}

		private Steema.TeeChart.Styles.Bar bar1;
		private bool first = true;
		double newValue;

		private void InitializeChart()
		{
			tChart1.Aspect.View3D = false;
			tChart1.Dock = DockStyle.Fill;

			bar1 = new Steema.TeeChart.Styles.Bar(tChart1.Chart);
			bar1.Marks.Visible = false;
			bar1.XValues.DateTime = true;

			Random rnd = new Random();

			for (int i = 0; i < 50; ++i)
			{
				bar1.Add(DateTime.Now.AddDays(i), rnd.Next(100), Color.Red);
			}

			tChart1.Panel.MarginBottom = 20;
			tChart1.Axes.Bottom.Labels.Angle = 90;
			tChart1.Axes.Bottom.Increment = Steema.TeeChart.Utils.GetDateTimeStep(Steema.TeeChart.DateTimeSteps.TwoDays);
			tChart1.GetNextAxisLabel += new Steema.TeeChart.GetNextAxisLabelEventHandler(tChart1_GetNextAxisLabel);
		}

		void tChart1_GetNextAxisLabel(object sender, Steema.TeeChart.GetNextAxisLabelEventArgs e)
		{
			double seriesIncrement = tChart1.Axes.Bottom.Increment;

			if (sender.Equals(tChart1.Axes.Bottom))
			{
				e.Stop = false;

				if (first)
				{
					newValue = e.LabelValue;
					first = false;
				}
				else
				{
					newValue += seriesIncrement;
				}

				if (e.LabelIndex == 0)
				{

					e.LabelValue = tChart1.Axes.Bottom.CalcPosPoint(tChart1.Axes.Left.Position);
					DateTime.FromOADate(e.LabelValue).ToShortDateString();

				}
				else
				{
					if (e.LabelIndex == tChart1[0].Count)
					{
						e.LabelValue = tChart1.Axes.Bottom.CalcPosPoint(tChart1.Axes.Bottom.IEndPos);
						DateTime.FromOADate(e.LabelValue).ToShortDateString();

					}
					else
					{
						if (e.LabelIndex < tChart1[0].Count)
						{
							e.LabelValue = newValue;
							DateTime.FromOADate(e.LabelValue).ToShortDateString();

						}
						else
						{
							e.Stop = true;
							first = true;
						}
					}
				}
			}
		}
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

qcrnd
Advanced
Posts: 214
Joined: Mon Sep 04, 2006 12:00 am

Re: Dates Range on the bottom axis - properties

Post by qcrnd » Sun Mar 21, 2010 8:10 am

Hi ,
I tried to use the new example , but I still have the same problem in the range is big.

If I don't try to change the label ,in resizing the tee chart is smart and know how to show part of the labels on redraw and it looks good.
I want the same behavior an on addition always to add the first and the last date in the range.
In all the examples that you send me - you shows custom labels, and when we add the custom labels on resizing there is a problem, the labels are draw on top of each other.
see the attached pic - with last example you send me
ex_new.JPG
ex_new.JPG (48.2 KiB) Viewed 19394 times

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Dates Range on the bottom axis - properties

Post by Narcís » Mon Mar 22, 2010 8:07 am

Hi qcrnd,

Have you tried bottom axis increment as I told you? Last example I posted doesn't add custom labels to the chart. They are modified in the GetNextAxisLabel event but no custom labels added.

Thanks in advance.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

qcrnd
Advanced
Posts: 214
Joined: Mon Sep 04, 2006 12:00 am

Re: Dates Range on the bottom axis - properties

Post by qcrnd » Thu Mar 25, 2010 3:01 pm

Hi
You can see the example project I used.
I copied your code to my example, try to resizing the dialog.
Ex.zip
(50.52 KiB) Downloaded 782 times

Thanks

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Dates Range on the bottom axis - properties

Post by Sandra » Fri Mar 26, 2010 11:41 am

Hello gcrnd,

We check your project, and the only problem we have seen, is that last two labels are overlapping. You can solve it changing value of increment, in its case change TwoDays for ThreeDays, as next example:

Code: Select all

 tChart1.Axes.Bottom.Increment = Steema.TeeChart.Utils.GetDateTimeStep(Steema.TeeChart.DateTimeSteps.ThreeDays);
Please, could you say it changing increment, your project works as you want?

I hope will helps.

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

qcrnd
Advanced
Posts: 214
Joined: Mon Sep 04, 2006 12:00 am

Re: Dates Range on the bottom axis - properties

Post by qcrnd » Wed Apr 07, 2010 6:09 am

Hi ,

This solution is not good for me , I want the Increment to be one day since when the range is only 3-4 days I want to see all the days.
And when the range of the data is 3-5 months , I want to see the first and the last date and only part of the dates in the middle.

In the solution that you suggest I also have problem on resizing the dialog ( see the images that I already attached in my previous comments).

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Dates Range on the bottom axis - properties

Post by Sandra » Wed Apr 07, 2010 8:53 am

Hello gcrnd,

I recommend that you use default labels, but put first and last dates as annotation tools, because there are same properties with labels manually dates. Please, check if annotation tools solve your problem.

I hope will helps.


Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

qcrnd
Advanced
Posts: 214
Joined: Mon Sep 04, 2006 12:00 am

Re: Dates Range on the bottom axis - properties

Post by qcrnd » Mon May 10, 2010 7:41 am

Hi

Since the solution that you gave is not working for me (you can see the attachments that I send you) .
Can you please tell how can I set the chart to show only the dates that we have data for them in the series?

Thanks

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Dates Range on the bottom axis - properties

Post by Sandra » Mon May 10, 2010 11:18 am

Hello gcrnd,
Can you please tell how can I set the chart to show only the dates that we have data for them in the series?
I have made a simple code that I think, you could use in your project. Please, check next code works as you want.

Code: Select all

public Form1()
        {
            InitializeComponent();
            InitializeChart();
        }
        private void InitializeChart()
        {
            tChart1.Aspect.View3D = false;
            Steema.TeeChart.Styles.Line line = new Steema.TeeChart.Styles.Line(tChart1.Chart);
            line.Marks.Visible = false;
            line.XValues.DateTime = true;
            line.Pointer.Visible = true;
            Random rnd = new Random();

            for (int i = 0; i < 10; ++i)
            {
               line.Add(DateTime.Now.AddDays(i), rnd.Next(100),DateTime.Now.AddDays(i).ToShortDateString(), Color.Red);
            }
            tChart1.Panel.MarginBottom = 20;
            tChart1.Axes.Bottom.Labels.Angle = 90;

I hope will helps.

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply