XAxis with more than 200 points shows date as 12/30/1899

2 posts, 0 answers
  1. Boots
    Boots avatar
    81 posts
    Member since:
    Dec 2008

    Posted 13 Oct 2011 Link to this post

    Hello,

    I'm hitting a problem when the RadChart is displaying more than 200 points all it displays for date is 12/30/2011.

    Here is a quick sample that repeats the problem.

    <UserControl 
        x:Class="ChartTest.MainPage"
        mc:Ignorable="d"
        Loaded="UserControl_Loaded"
        d:DesignHeight="300" d:DesignWidth="400">
     
        <Grid x:Name="LayoutRoot" Background="White">
            <telerik:RadChart x:Name="chart">
                <telerik:RadChart.SeriesMappings>
                    <telerik:SeriesMapping>
                        <telerik:SeriesMapping.SeriesDefinition>
                            <telerik:AreaSeriesDefinition AxisName="YAxis" ShowItemLabels="False" ShowPointMarks="False">
                                <telerik:AreaSeriesDefinition.InteractivitySettings>
                                    <telerik:InteractivitySettings SelectionMode="Single" SelectionScope="Item" HoverScope="Item" />
                                </telerik:AreaSeriesDefinition.InteractivitySettings>
                            </telerik:AreaSeriesDefinition>
                        </telerik:SeriesMapping.SeriesDefinition>
                        <telerik:SeriesMapping.ItemMappings>
                            <telerik:ItemMapping FieldName="Date" DataPointMember="XCategory" />
                            <telerik:ItemMapping FieldName="Count" DataPointMember="YValue" />
                        </telerik:SeriesMapping.ItemMappings>
                    </telerik:SeriesMapping>
                    <telerik:SeriesMapping>
                        <telerik:SeriesMapping.SeriesDefinition>
                            <telerik:LineSeriesDefinition AxisName="SecondYAxis"  ShowItemLabels="False" ShowPointMarks="False">
                                <telerik:LineSeriesDefinition.InteractivitySettings>
                                    <telerik:InteractivitySettings SelectionMode="Single" SelectionScope="Item" HoverScope="Item" />
                                </telerik:LineSeriesDefinition.InteractivitySettings>
                            </telerik:LineSeriesDefinition>
                        </telerik:SeriesMapping.SeriesDefinition>
                        <telerik:SeriesMapping.ItemMappings>
                            <telerik:ItemMapping FieldName="Date" DataPointMember="XCategory" />
                            <telerik:ItemMapping FieldName="Quantity" DataPointMember="YValue" />
                        </telerik:SeriesMapping.ItemMappings>
                    </telerik:SeriesMapping>
                </telerik:RadChart.SeriesMappings>
                <telerik:RadChart.DefaultView>
                    <telerik:ChartDefaultView ChartLegendPosition="Bottom">
                        <telerik:ChartDefaultView.ChartArea>
                            <telerik:ChartArea LabelFormatBehavior="HumanReadable">
                                <telerik:ChartArea.AxisY>
                                    <telerik:AxisY AxisName="YAxis" Title="Deliveries"  />
                                </telerik:ChartArea.AxisY>
                                <telerik:ChartArea.AdditionalYAxes>
                                    <telerik:AxisY AxisName="SecondYAxis" Title="Quantity" />
                                </telerik:ChartArea.AdditionalYAxes>
                                <telerik:ChartArea.AxisX>
                                    <telerik:AxisX LabelRotationAngle="90" LabelStep="2" DefaultLabelFormat="d"  />
                                </telerik:ChartArea.AxisX>
                            </telerik:ChartArea>
                        </telerik:ChartDefaultView.ChartArea>
                        <telerik:ChartDefaultView.ChartTitle>
                            <telerik:ChartTitle Visibility="Collapsed" />
                        </telerik:ChartDefaultView.ChartTitle>
                        <telerik:ChartDefaultView.ChartLegend>
                            <telerik:ChartLegend Visibility="Collapsed" />
                        </telerik:ChartDefaultView.ChartLegend>
                    </telerik:ChartDefaultView>
                </telerik:RadChart.DefaultView>
            </telerik:RadChart>
        </Grid>
    </UserControl>
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Windows;
    using System.Windows.Controls;
     
    namespace ChartTest
    {
        public partial class MainPage : UserControl
        {
            public MainPage()
            {
                InitializeComponent();
            }
     
            private void UserControl_Loaded(object sender, RoutedEventArgs e)
            {
                List<Driver> drivers = new List<Driver>();
                Random random = new Random();
                drivers = Enumerable.Range(0, 200).Select(i => new Driver() { Count = random.Next(), Quantity = random.Next(), Date = DateTime.Now.AddDays(i) }).ToList<Driver>();
                this.chart.ItemsSource = drivers;
            }
        }
     
        public class Driver
        {
            private int _count;
            private double _quantity;
            private DateTime _date;
     
            public int Count
            {
                get { return this._count; }
                set { this._count = value; }
            }
             
            public double Quantity
            {
                get { return this._quantity; }
                set { this._quantity = value; }
            }
             
            public DateTime Date
            {
                get { return this._date; }
                set { this._date = value; }
            }
        }
    }

    Any idea's what I'm doing wrong?

    Thanks much,
    ~Boots
  2. Peshito
    Admin
    Peshito avatar
    585 posts

    Posted 18 Oct 2011 Link to this post

    Hi Boots,

    When there are more then 200 data points, the chart sampling functionality is enabled, also in your case you are using XCategory as a DataPointMember which cannot be sampled, as these values are strings. To resolve that, use XValue instead, or turn off the sampling feature.

    More about sampling can be found here.

    Best wishes,
    Peshito
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Back to Top