SereiesMapping and dateTime

2 posts, 1 answers
  1. andrea bellagamba
    andrea  bellagamba avatar
    43 posts
    Member since:
    Jul 2009

    Posted 29 Jun 2010 Link to this post

    Hi I am using a RadChart (version 2010.1.0422.1040) to display 3 series.
    Each serie's point is a GraphPoint instance, with a Date and a Value:
    public class GraphPoint
        public DateTime Date;
        public double Value;

        public GraphPoint(DateTime date, double value)
          this.Date = date;
          this.Value = value;

    this is teh code thst defines my chart, the SetData method is called with a list of Traffic object containing valid data:
        /// Set the traffic data.
        /// </summary>
        /// <param name="traffic">The traffic.</param>
        public void SetData(List<Traffic> traffic)
          this.TrafficChart.ItemsSource = null;     
          this.TrafficChart.DefaultView.ChartArea.AxisX.AutoRange = true;

          var visitSerie = this.SerieDefinition("Visit");
          var valueSerie = this.SerieDefinition("Value");

          visitSerie.CollectionIndex = 0;
          valueSerie.CollectionIndex = 1;


          var visitData = (from t in traffic select new GraphPoint(t.Date, t.Visits)).ToList();
          var valueData = (from t in traffic select new GraphPoint(t.Date, t.Value)).ToList();

          var trafficTimeline = new List<List<GraphPoint>>

          this.TrafficChart.DefaultView.ChartArea.AxisX.IsDateTime = true;
          this.TrafficChart.DefaultView.ChartArea.AxisX.DefaultLabelFormat = "dd-MMM-yyyy";

          this.TrafficChart.ItemsSource = trafficTimeline;

        /// <summary>
        /// Series the definition.
        /// </summary>
        /// <param name="serieName">Name of the serie.</param>
        /// <returns>The definition.</returns>
        protected SeriesMapping SerieDefinition(string serieName)
          var seriesMapping = new SeriesMapping
            LegendLabel = serieName,
            SeriesDefinition = new LineSeriesDefinition()
              ShowItemLabels = false,
              ShowItemToolTips = true

          seriesMapping.SeriesDefinition.Appearance.StrokeThickness = 2d;

          var itemMappingX = new ItemMapping("Date"DataPointMember.XValue);
          var itemMappingY = new ItemMapping("Value"DataPointMember.YValue);      


          return seriesMapping;

    When assigning the:
    this.TrafficChart.ItemsSource = trafficTimeline;

    I get this error:

    Invalid cast from 'DateTime' to 'Double'.

    can yuo explain why since I have specified the DefaultView.ChartArea.AxisX.IsDateTime = true;
    and mapper the Date property to the XValue
    var itemMappingX = new ItemMapping("Date"DataPointMember.XValue);

  2. Answer
    Ves avatar
    2926 posts

    Posted 01 Jul 2010 Link to this post

    Hello Andrea,

    Binding to fields is not supported. Please, promote the fields in GraphPoint class to properties and you will not experience such issues.

    Best regards,
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top