Why is my chart not showing X axis labels?

4 posts, 0 answers
  1. DAVE
    DAVE avatar
    19 posts
    Member since:
    Jun 2010

    Posted 28 Dec 2014 Link to this post

    My X axis is only displaying one label and I can't figure out why.

    double y;
    DateTime x;

    LineSeries series = new LineSeries();
    series.BorderWidth = 1;
    DateTime now = new DateTime(2015, 1, 2, 4, 0, 0, 950);
    for (int i = 0; i < 100; i++)
    {
    y = Math.Sin((double)(i) * 0.2);
    x = now.AddMilliseconds(i);
    series.DataPoints.Add(new CategoricalDataPoint(y, x));
    }

    DateTimeContinuousAxis axis = new DateTimeContinuousAxis();
    axis.PlotMode = AxisPlotMode.OnTicks;
    axis.LabelFormat = "{0:s.fff}";
    series.HorizontalAxis = axis;

    chart1.Series.Add(series);
  2. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 30 Dec 2014 Link to this post

    Hi Dave,

    Thank you for writing.

    The observed result is expected, as you are the category to:
    x = now.AddMilliseconds(i);

    and by the time the for loop ends, one category are being created. You can check that by printing the values of the categories after they are added to the series:
    foreach (CategoricalDataPoint dp in series.DataPoints)
    {
        Console.WriteLine(dp.Category);
    }

    I hope that you find this information useful. Should you have any other questions, do not hesitate to contact us.

    Regards,
    Stefan
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for WinForms is Visual Studio 2017 Ready
  4. DAVE
    DAVE avatar
    19 posts
    Member since:
    Jun 2010

    Posted 31 Dec 2014 in reply to Stefan Link to this post

    But I thought by using DateTimeContinuousAxis categories would NOT be used?
  5. Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 05 Jan 2015 Link to this post

    Hi Dave,

    Thank you for writing back.

    The issue with only one label visible is actually caused by a caching mechanism inside the chart axis. The problem is that the axis caches label elements and uses their content as key for the cache storage. The issue is only observed when using labels with milliseconds and is caused because the axis calls the ToString method of the DateTime object that is the category of each data point. This results in a string that does not contain the milliseconds part and therefore for all labels the same element is returned and drawn in the chart area. I have logged this issue in our feedback portal. You can track the progress of the issue, add your vote or comment to it and subscribe for status change alerts on the following link - Feedback item. Unfortunately, due to the nature of the issue, I am not able to provide you with a workaround. 

    I have also updated your Telerik Points for bringing this issue to our attention.

    As to the categories being used in a DateTimeContinuousAxis. The mechanism for generating labels is pretty much the same for DateTimeCategorical and continuous axes. The difference is in the layout of these labels. So strictly speaking these are not categories but formally they are pretty similar.

    I hope this will be useful. If you have further questions, I would be glad to assist.

    Regards,
    Ivan Petrov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top