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