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

SereiesMapping and dateTime

1 Answer 58 Views
Chart
This is a migrated thread and some comments may be shown as answers.
andrea bellagamba
Top achievements
Rank 1
andrea bellagamba asked on 29 Jun 2010, 09:59 AM
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:
    
    ///
 <summary>
    /// Set the traffic data.
    /// </summary>
    /// <param name="traffic">The traffic.</param>
    public void SetData(List<Traffic> traffic)
    {
      this.TrafficChart.ItemsSource = null;     
      this.TrafficChart.SeriesMappings.Clear();
      this.TrafficChart.DefaultView.ChartArea.AxisX.AutoRange = true;

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

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

      this.TrafficChart.SeriesMappings.Add(visitSerie);
      this.TrafficChart.SeriesMappings.Add(valueSerie);






      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>>
      {
        visitData,
        valueData
      };

      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);      

      seriesMapping.ItemMappings.Add(itemMappingX);
      seriesMapping.ItemMappings.Add(itemMappingY);

      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);


1 Answer, 1 is accepted

Sort by
0
Accepted
Ves
Telerik team
answered on 01 Jul 2010, 11:30 AM
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,
Ves
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
Tags
Chart
Asked by
andrea bellagamba
Top achievements
Rank 1
Answers by
Ves
Telerik team
Share this question
or