This is a migrated thread and some comments may be shown as answers.

Why is my chart not showing X axis labels?

3 Answers 765 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
DAVE
Top achievements
Rank 1
DAVE asked on 28 Dec 2014, 06:01 AM
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);

3 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 30 Dec 2014, 02:37 PM
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.

 
0
DAVE
Top achievements
Rank 1
answered on 31 Dec 2014, 08:57 PM
But I thought by using DateTimeContinuousAxis categories would NOT be used?
0
Ivan Petrov
Telerik team
answered on 05 Jan 2015, 04:21 PM
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.

 
Tags
ChartView
Asked by
DAVE
Top achievements
Rank 1
Answers by
Stefan
Telerik team
DAVE
Top achievements
Rank 1
Ivan Petrov
Telerik team
Share this question
or