Page 1 of 5

X asix labels not lining up properly

Posted: Thu May 20, 2010 8:49 pm
by 15654268
I have a chart that is plotting weekly summary data using a bar graph but I can'y get the x axis labels to line up properly. The data starts 29 Mar 2009 and ends 9 May 2010 in weekly increments, if I plot this data using a bar series I can the following.
21-05-2010 6-27-43 AM.png
21-05-2010 6-27-43 AM.png (12.83 KiB) Viewed 100125 times
As you can see the first label is 01 April 09, what I need is for the bar to have the correct label of 29 Mar 09 and for the label to be centered under the bar.
I've tried several different axis options but no matter what I try I can't get the labels to line up properly, If I increase the size of the chart (see next image) the labels change but still do not line up properly with the bars. Am I missing something here or is this a bug?
21-05-2010 6-33-20 AM.png
21-05-2010 6-33-20 AM.png (6.73 KiB) Viewed 100130 times
Here are sone screen shots of relevant properties pages
21-05-2010 6-42-11 AM.png
21-05-2010 6-42-11 AM.png (95.11 KiB) Viewed 100129 times
I'm using Tchart 4.0.2009.62330 in a VS2003 VB environment

Re: X asix labels not lining up properly

Posted: Thu May 20, 2010 9:32 pm
by 15654268
Additional:
I've just downloaded the latest build 4.0.2010.13050 and tried that with the same results.

One thing I've noticed that may be related is that I can't seem to change the Offset: value on the bottom axis, it is set to 8 and if I change it to say 0, when I view the axis properties again it is back at 8.

Re: X asix labels not lining up properly

Posted: Fri May 21, 2010 2:42 pm
by yeray
Hi Captell,

If I understood well, what you should do is to add your values with labels:

Code: Select all

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

            Steema.TeeChart.Styles.Bar bar1 = new Steema.TeeChart.Styles.Bar(tChart1.Chart);
            bar1.Marks.Style = Steema.TeeChart.Styles.MarksStyles.Value;
            bar1.XValues.DateTime = true;

            tChart1.Axes.Bottom.Increment = Steema.TeeChart.Utils.GetDateTimeStep(Steema.TeeChart.DateTimeSteps.OneWeek);
            tChart1.Axes.Bottom.Labels.Angle = 90;

            Random rnd = new Random();
            for (int i = 0; i < 10; i++)
            {
                DateTime date = DateTime.Parse("29/03/2009").AddDays(7*i);
                bar1.Add(date, rnd.Next(100), date.ToString("MMM dd"));
            }
        }

Re: X asix labels not lining up properly

Posted: Sat May 22, 2010 2:43 am
by 15654268
Yes I could do that but in previous releases I didn't need to, the labels lined up correctly with the bars.
In any event it would be problematic for me to have to add the data with labels as I'm not hard coding the chart definitions, my users can design their own charts.
By adding the data using labels rather than the datetime value I loose the ability for the user to change the format of the labels etc. using the Axis editor.

Re: X asix labels not lining up properly

Posted: Mon May 24, 2010 8:48 am
by yeray
Hi Captell,

In that case, I think the best option would be using custom labels:

Code: Select all

        private void InitializeChart()
        {
            tChart1.Aspect.View3D = false;
            tChart1.Panel.MarginBottom = 15;

            Steema.TeeChart.Styles.Bar bar1 = new Steema.TeeChart.Styles.Bar(tChart1.Chart);
            bar1.Marks.Style = Steema.TeeChart.Styles.MarksStyles.Value;
            bar1.XValues.DateTime = true;

            tChart1.Axes.Bottom.Labels.Angle = 90;
            tChart1.Axes.Bottom.Labels.DateTimeFormat = "MMM dd";

            Random rnd = new Random();
            for (int i = 0; i < 10; i++)
            {
                DateTime date = DateTime.Parse("29/03/2009").AddDays(7 * i);
                bar1.Add(date, rnd.Next(100));//, date.ToString("MMM dd"));
            }

            RecalcBottomLabels();
        }

        private void RecalcBottomLabels()
        {
            tChart1.Axes.Bottom.Labels.Items.Clear();
            for (int i = 0; i < tChart1[0].Count; i++)
            {
                tChart1.Axes.Bottom.Labels.Items.Add(tChart1[0].XValues[i], DateTime.FromOADate(tChart1[0].XValues[i]).ToString(tChart1.Axes.Bottom.Labels.DateTimeFormat));
            }
        }
Captell wrote:Yes I could do that but in previous releases I didn't need to, the labels lined up correctly with the bars.
Could you please tell us in what release were you experiencing a different behaviour?
Could you also post a simple example snipped of code we can run as-is to reproduce this difference of behaviour between releases?

Thanks in advance.

Re: X asix labels not lining up properly

Posted: Mon May 24, 2010 5:17 pm
by 14045174
Hi! I am having the same problem with bar charts. My users are complaining, that when they select just a few points on a time line and the points are representing end of year dates (say, 15th of December each year) and show their data as bar graphs, the labels at the bottom will randomly select a month to show and it is always not centered. The usual question from my client is: "Why, if I select a specific month for the first point, the chart starts with anything BUT the selected month, when the axis is set to automatic?" (same will apply to a specific date, selected by another client) My problem: I cannot use labels for the bottom axis as well as custom drawing, since we are talking about a few thousand clients each having a few hundreds of graphs and not all of them are showing dates on bottom axis. In fact, I have very little control on what they can show on the graph. As to the dates on the bottom axis - clients like to format them differently, set up increment as they need, and unless I will re-implement all your labels drawing logic in my custom Draw Labels, I will have more problems, than I can solve.

Re: X asix labels not lining up properly

Posted: Tue May 25, 2010 1:53 am
by 15654268
I'm not sure excatly which version this bug appeared in but it definately was not present in release 3.5.3146.24804.
25-05-2010 11-40-10.png
25-05-2010 11-40-10.png (6.3 KiB) Viewed 100044 times

Re: X asix labels not lining up properly

Posted: Tue May 25, 2010 9:03 am
by yeray
Hi Captell and UserLS,

It would be helpful if you could send us a simple example project we can run as-is to reproduce the problem here.
I'm trying to obtain the chart in the last picture from Captell in v3.5.3146 but I can't with the following code:

Code: Select all

            tChart1.Aspect.View3D = false;
            tChart1.Panel.MarginBottom = 15;

            Steema.TeeChart.Styles.Bar bar1 = new Steema.TeeChart.Styles.Bar(tChart1.Chart);
            bar1.Marks.Style = Steema.TeeChart.Styles.MarksStyles.Value;
            bar1.XValues.DateTime = true;

            tChart1.Axes.Bottom.Labels.Angle = 90;
            tChart1.Axes.Bottom.Labels.DateTimeFormat = "MMM dd";
            tChart1.Axes.Bottom.Increment = Steema.TeeChart.Utils.GetDateTimeStep(Steema.TeeChart.DateTimeSteps.OneWeek);

            Random rnd = new Random();
            for (int i = 0; i < 10; i++)
            {
                DateTime date = DateTime.Parse("29/03/2009").AddDays(7 * i);
                bar1.Add(date, rnd.Next(100));
            }

Re: X asix labels not lining up properly

Posted: Wed May 26, 2010 3:48 pm
by 14045174
Ok, here is the code that reproduces the chart below using the latest released version of TChart:

Code: Select all

            _testChart.Clear();
            var bar = new Bar(_testChart.Chart) {Marks = {Style = MarksStyles.XValue}};
            bar.XValues.DateTime = true;

            _testChart.Axes.Bottom.Labels.Angle = 90;
            _testChart.Axes.Bottom.Labels.DateTimeFormat = "MMM dd";
            _testChart.Axes.Bottom.Increment = Utils.GetDateTimeStep(DateTimeSteps.OneYear);

            var rnd = new Random();
            var date = DateTime.Now;
            for (var i = 0; i < 10; i++)
                bar.Add(date.AddYears(i), rnd.Next(100));
Note that bottom axis is set to automatic maximum and minimum, none of the points selected are from January, so the question is "Why January is showing up at all?" By setting increment to 365 instead of OneYear, setting Labels.RoundFirst to false and playing with axis Min/Max offsets I can get it to display the correct month (forget about dates!), but in my case it is not going to work, since my clients setup graphs using relative dates (year from today, 6 months from end of last month, etc.) and than print reports every month, or quarter without readjusting them ever after and expect to see the correct dates.
Chart1.png
Chart1.png (15.55 KiB) Viewed 100005 times
Here is similar problem with monthly dates:

Code: Select all

            _testChart.Clear();

            var bar = new Bar(_testChart.Chart) {Marks = {Style = MarksStyles.XValue}};
            bar.XValues.DateTime = true;

            _testChart.Axes.Bottom.Labels.Angle = 90;
            _testChart.Axes.Bottom.Labels.DateTimeFormat = "MMM dd";
            _testChart.Axes.Bottom.Increment = Utils.GetDateTimeStep(DateTimeSteps.OneMonth);

            var rnd = new Random();
            var date = DateTime.Now;
            for (var i = 0; i < 10; i++)
                bar.Add(date.AddMonths(i), rnd.Next(100));
Chart2.png
Chart2.png (13.83 KiB) Viewed 100010 times

Re: X asix labels not lining up properly

Posted: Thu May 27, 2010 2:27 pm
by yeray
Hi UserLS and Captell,

Thanks for the samples, UserLS.
I can see strange behaviour that needs to be analysed further so I've added it to the wish list to be revised for future releases (TF02014914).

A) XValues.DateTime. The labels are automatically aligned as you expect if you set the property after populating the series, but before.

Code: Select all

            Steema.TeeChart.Styles.Bar bar1 = new Steema.TeeChart.Styles.Bar(tChart1.Chart);

            bar1.Marks.Style = Steema.TeeChart.Styles.MarksStyles.XValue;
            //bar1.XValues.DateTime = true; //non-alignment
            tChart1.Axes.Bottom.Labels.Angle = 90;
            tChart1.Axes.Bottom.Labels.DateTimeFormat = "MMM dd";
            tChart1.Axes.Bottom.Increment = Steema.TeeChart.Utils.GetDateTimeStep(Steema.TeeChart.DateTimeSteps.OneDay);

            bar1.FillSampleValues();

            bar1.XValues.DateTime = true; //alignment
B) FillSampleValues. This automatic alignment only seems to work with FillSampleValues. If you change it for the following, the bottom axes labels are non-aligned again (regardless of XValues.DateTime place):

Code: Select all

            Steema.TeeChart.Styles.Bar bar1 = new Steema.TeeChart.Styles.Bar(tChart1.Chart);

            bar1.Marks.Style = Steema.TeeChart.Styles.MarksStyles.XValue;
            tChart1.Axes.Bottom.Labels.Angle = 90;
            tChart1.Axes.Bottom.Labels.DateTimeFormat = "MMM dd";
            tChart1.Axes.Bottom.Increment = Steema.TeeChart.Utils.GetDateTimeStep(Steema.TeeChart.DateTimeSteps.OneDay);

            Random rnd = new Random();
            DateTime date = DateTime.Now;
            for (var i = 0; i < 10; i++)
                bar1.Add(date.AddDays(i), rnd.Next(100));

            bar1.XValues.DateTime = true;

Re: X asix labels not lining up properly

Posted: Sat Jun 05, 2010 5:50 am
by 15654268
Hi all,
I was just wondering if there is any update on this one?

Re: X asix labels not lining up properly

Posted: Mon Jun 07, 2010 8:54 am
by yeray
Hi Captell,

I'm afraid not yet. I recommend you to be aware at this forum or subscribe to our RSS news feed for new release announcements and what's implemented on them.

Re: X asix labels not lining up properly

Posted: Sun Jun 27, 2010 12:47 am
by 15654268
Hi there,
I just downloaded the June 2010 release 4.0.2010.27960 and this problem is still not fixed. This is really important to my clients, can you tell me when it will be resolved please.

Re: X asix labels not lining up properly

Posted: Mon Jun 28, 2010 8:01 am
by narcis
Hello,

I'm not able to commit to a specific date but I have increased issue's priority in the list to be revised.

Re: X asix labels not lining up properly

Posted: Tue Jul 27, 2010 12:53 pm
by yeray
Hi UserLS and Captell,

After studying the (TF02014914) issue, we concluded that (B) would be a designed behaviour rather than a bug. Let me explain:
The same happens with normal labels:

Code: Select all

   private void InitializeChart()
   {
     tChart1.Series.Add(typeof(Bar));
     Random rnd = new Random();

     for (int i = 0; i < 50; i++)
     {
       if (i % 5 == 0 && i % 10 != 0)
       {
         tChart1[0].Add(i, rnd.NextDouble());
       }
     }

     tChart1.Axes.Bottom.Increment = 10;
   } 
Chart1.png
Chart1.png (18.5 KiB) Viewed 99886 times
If you don't specify where the labels should be drawn, we think one would expect them to be drawn at 0, 1, 2 etc, and if you set the increment to be 10, the labels should be at 0, 10, 20 etc. Where otherwise?
And furthermore, if you add more data, breaking the regularity:

Code: Select all

            for (int i = 50; i < 100; i++)
            {
                if (i % 10 == 0)
                {
                    tChart1[0].Add(i, rnd.NextDouble());
                }
            } 
Chart2.png
Chart2.png (19.95 KiB) Viewed 99889 times
If we had changed axis labels to start drawing (5, 15, 25 etc.) they would now be "wrong" when new data added, right?

We could add a new property into axis labels (DrawAtPointValue or something similar) which would only draw labels on the axis where the series has a point. The problem will be that if there was a gap between one point and the next then there would be no axis labels. This is, in effect, identical to adding in point labels using the Series.Add overload.

Code: Select all

tChart1[0].Add(date.AddDays(i), rnd.Next(100), date.AddDays(i).ToString("MMM dd"));