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

Dates Range on the bottom axis - properties

Post by qcrnd » Mon Feb 15, 2010 7:22 am

Hello,

I have a chart that the bottom axis is dates range .I set the "Increment" property to show days, but sometimes when the range is too big and it may include 2-3 months. In this case the chart don't show some of the days since we don't have enough space. How can we make the chart to show always the first and the last day in the given range?

Can you please tell me what property to change in order to show always the first and the last date of the range in the bottom axis.

Thanks
Kety

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 Feb 15, 2010 9:50 am

Hello gcrnd,

I made a simple example of dateTime that you can use in your application, please check next code works as you want.

Code: Select all

 public Form1()
        {
            InitializeComponent();
            InitializeChart();
        }
        private Steema.TeeChart.Styles.Bar bar1;
        private void InitializeChart()
        {
            bar1 = new Steema.TeeChart.Styles.Bar(tChart1.Chart);
            Random rnd = new Random(); 
            DateTime today = DateTime.Today; 
            TimeSpan oneDay = TimeSpan.FromDays(15); 
            bar1.XValues.DateTime = true;
            for (int i = 1; i <= 25; ++i)
            {
                bar1.Add(today, rnd.Next(100), Color.Red);
                today += oneDay;
            }
            tChart1.Axes.Bottom.Labels.Angle = 90;
            Steema.TeeChart.Axis bottomAxis = tChart1.Axes.Bottom; 
            bottomAxis.Increment = Steema.TeeChart.Utils.GetDateTimeStep(Steema.TeeChart.DateTimeSteps.TwoDays);
 
        }
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 Feb 18, 2010 4:04 pm

Hi Sandra,

My code is similar to your bu in the increment property I set it to one day.
If the range of the data is a few days - it works ok , since it show me all the days.

The problems is when the range have data from dates of a few month.
Then I see only part of the dates since we don't have enough space.
I want set the chart properties to display always the first and the last day in the range

Thanks
Kety

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 Feb 19, 2010 9:34 am

Hello Kety,

I think that you should customize that using the GetNextAxisLabel event as shown in the examples on those threads:

http://www.teechart.net/support/viewtopic.php?t=8392
http://www.teechart.net/support/viewtopic.php?t=4552

Hope this 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 Feb 22, 2010 2:52 pm

Hi,

They have a different problem then mine, in the other case they have always the problem.
In mine case it appears only when the range is large ( not related to offset) and there is no place to draw all the legends.
You can see in attachments 1.bmp (the first day do not appears in the bottom axis) and in 2.bmp (it is OK)
My code is per day, since I want to see the date format in days:
m_thresholdValuesChart.Axes.Bottom.Increment = Steema.TeeChart.Utils.GetDateTimeStep(Steema.TeeChart.DateTimeSteps.OneDay);
m_thresholdValuesChart.Axes.Left.Increment = 1;
m_thresholdValuesChart.Axes.Left.Labels.ValueFormat = "0";

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

Re: Dates Range on the bottom axis - properties

Post by qcrnd » Mon Feb 22, 2010 2:53 pm

1.JPG
1.JPG (22.37 KiB) Viewed 21268 times
2.JPG
2.JPG (17.18 KiB) Viewed 21264 times

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 Feb 23, 2010 9:39 am

Hello gcrnd,
In mine case it appears only when the range is large ( not related to offset) and there is no place to draw all the legends.
You can see in attachments 1.bmp (the first day do not appears in the bottom axis) and in 2.bmp (it is OK)
In that case, and as mentioned on the threads I pointed, we recommend using custom axis labels. You may also be interested on reading the thread below which covers most possibilities about label customization. Please notice it's a multiple page thread and what you are looking for may not appear in first pages http://www.teechart.net/support/viewtop ... f=4&t=2989


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 » Tue Feb 23, 2010 2:52 pm

Hi ,

I tied to use custom axis labels,this mean that we need to add manually the labels.
I have a new problem , I want to add the label only if I have enough space in the bottom axis.
How can I recognize this case.I want to add a new label, only if it is not interfere on the previous label.
(see the attachment in this case the new label is paint on top of the previous label).
(my code is :
m_thresholdValuesChart.Axes.Bottom.Labels.Items.Clear();

for (int i = 0; i < m_grid.DataSet.Count; i++)
{
IThresholdValue thresholdValue = (IThresholdValue)m_grid.DataSet;
m_thresholdValuesChart.Axes.Bottom.Labels.Items.Add(m_warningSeries.XValues,
thresholdValue.Date.ToShortDateString());
}
)
3.JPG
3.JPG (28.93 KiB) Viewed 21254 times
Thanks

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Dates Range on the bottom axis - properties

Post by Yeray » Tue Feb 23, 2010 3:41 pm

Hi qcrnd,

In the first page in the thread that Sandra pointed to you in the last post there is an example from Narcís where tries to avoid overlapping. Here is what was suggested on that post:

24 Oct 2005 15:08
Narcís wrote:Hello everyone,

You could implement something like the code below in the OnAfterDraw event and do what you want when labels overlap.

Code: Select all

		private void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
		{ 			
			tChart1.Header.Text="";

			Steema.TeeChart.AxisLabelItem CurrentLabel, PreviousLabel;	
			for (int i=1; i<tChart1.Axes.Left.Labels.Items.Count; ++i)
			{ 
				CurrentLabel = tChart1.Axes.Left.Labels.Items[i];
				PreviousLabel = tChart1.Axes.Left.Labels.Items[i-1];

				tChart1.Header.Text=tChart1.Header.Text+" "+CurrentLabel.Top.ToString();

				if (CurrentLabel.Top+CurrentLabel.Height == PreviousLabel.Top)
				{
					CurrentLabel.Visible=false;
				}
			}
		}
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

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

Re: Dates Range on the bottom axis - properties

Post by qcrnd » Wed Feb 24, 2010 7:27 am

Hi ,

I try to use the example that you send me and to change it for the bottom axis?(in the example we have the left axis) , but it seems that I am not taking the location of the labels correctly.
My code is the following :
private void OnChartAfterDraw(object sender, Graphics3D g)
{
Steema.TeeChart.AxisLabelItem CurrentLabel, PreviousLabel;
PreviousLabel = m_thresholdValuesChart.Axes.Bottom.Labels.Items[0];
for (int i = 1; i < m_thresholdValuesChart.Axes.Bottom.Labels.Items.Count; ++i)
{
CurrentLabel = m_thresholdValuesChart.Axes.Bottom.Labels.Items;
if (CurrentLabel.Left< PreviousLabel.Left + PreviousLabel.Height)
{
CurrentLabel.Visible = false;
}
else
{
CurrentLabel.Visible = false;
PreviousLabel = CurrentLabel;
}
}
}
I get negative values for "CurrentLabel.Left" and "PreviousLabel.Left".

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 » Wed Feb 24, 2010 10:39 am

Hello gcrnd,

Please, you could modify your code as next example and check if it works as you want. If you don’t like solution or doesn’t work correctly, please send us a simple project, because we can reproduce exactly issue here and help to solve it.

Code: Select all

           private Steema.TeeChart.Styles.Bar bar1;
        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();
            DateTime today = DateTime.Today;
            TimeSpan oneDay = TimeSpan.FromDays(1);
            bar1.XValues.DateTime = true;
            for (int i = 1; i <= 55; ++i)
            {
                bar1.Add(today, rnd.Next(100), Color.Red);
                today += oneDay;
            }
            tChart1.Axes.Bottom.Labels.Items.Clear();
            for (int i = 0; i <bar1.Count ; i++)
            {
                tChart1.Axes.Bottom.Labels.Items.Add(bar1.XValues[i], DateTime.FromOADate(bar1.XValues[i]).ToShortDateString());                
            }

            tChart1.Axes.Bottom.Labels.Angle = 90;
            tChart1.Axes.Bottom.Increment = Steema.TeeChart.Utils.GetDateTimeStep(Steema.TeeChart.DateTimeSteps.OneDay);
            tChart1.AfterDraw +=new Steema.TeeChart.PaintChartEventHandler(tChart1_AfterDraw);
            tChart1.Draw();

        }
        private void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
        {
            tChart1.Header.Text = "";
            Steema.TeeChart.AxisLabelItem CurrentLabel, PreviousLabel;
            for (int i = 1; i < tChart1.Axes.Bottom.Labels.Items.Count; ++i)
            {               
                CurrentLabel = tChart1.Axes.Bottom.Labels.Items[i];
                PreviousLabel = tChart1.Axes.Bottom.Labels.Items[i - 1];
                if (CurrentLabel.Left+CurrentLabel.Height == PreviousLabel.Left)
                {
                    CurrentLabel.Visible = false;
                }
            }
        }
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 Feb 25, 2010 3:28 pm

Hi

See the attache project example in order to reproduce the problem.
When we enlarge the dialog the dates are ok , when we change the dialog to small size the dates are not clear.

Thanks
Attachments
WindowsFormsApplication.zip
(23.48 KiB) Downloaded 669 times

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 Feb 26, 2010 10:08 am

Hello gcrnd,

Please, see this thread where there are explained everything must be done to solve the problem of overlapping axis labels. I recommend to go concretely at third, fourth and fifth pages.

Those examples look if overlapping labels and paint as much as possible without being over-write. If you want to paint all labels you must do the range of the chart axes smaller or larger chart as being done in thread examples.



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 Feb 28, 2010 8:56 am

Hi

Maybe I misunderstand the solution, but how the "gauge" property is related the my problem?
As you see in the example that I send you , I want to know on "OnChartAfterDraw" method ,which label to set to visible and which to set to be invisible.
On resizing it will be change -because it depends if I have enough space to draw all the label.The only problem is that I don't know to check if the new label will be paint on top of the previous or a new location on the screen.

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 01, 2010 9:15 am

Hello gcrnd,

Sorry!
I apologize for my confusion; I have suggested an incorrect thread.Please see this thread now if that is correct.

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