I'm trying to plot a “stepline” chart where AxisX is a DateTime and some points are nulls.
As I didn't find any specific series (I hope you'll address soon), I use LineSeriesDefinizion doubling data point (see code) but:
- null value are treated as 0 (wrong since 0 means 0 value while null means missing value)
- where first value is null, the control throws a NullReferenceException
public MainWindow()
{
InitializeComponent();
ConfigureChart();
}
private void ConfigureChart()
{
LineSeriesDefinition lineSeries = new LineSeriesDefinition();
lineSeries.ShowItemLabels = false;
lineSeries.ShowPointMarks = false;
SeriesMapping actualMapping = new SeriesMapping();
actualMapping.SeriesDefinition = lineSeries;
actualMapping.LegendLabel = "Data";
actualMapping.ItemMappings.Add(new ItemMapping("Day", DataPointMember.XValue));
actualMapping.ItemMappings.Add(new ItemMapping("Value", DataPointMember.YValue));
radChart.SeriesMappings.Add(actualMapping);
radChart.DefaultView.ChartArea.AxisX.DefaultLabelFormat = "#VAL{dd-MM-yy}";
radChart.DefaultView.ChartArea.AxisX.LabelRotationAngle = 45;
radChart.DefaultView.ChartArea.AxisX.IsDateTime = true;
radChart.ItemsSource = MyData.GetData();
}
}
class MyData
{
public DateTime Day { get; set; }
public double? Value { get; set; }
public static List<MyData> GetData()
{
DateTime today = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
List<MyData> list = new List<MyData>();
list.Add(new MyData() { Day = today, Value = null });
list.Add(new MyData() { Day = today.AddDays(1), Value = 1 });
list.Add(new MyData() { Day = today.AddDays(1), Value = 2 });
list.Add(new MyData() { Day = today.AddDays(2), Value = 2 });
list.Add(new MyData() { Day = today.AddDays(2), Value = 1.5 });
list.Add(new MyData() { Day = today.AddDays(3), Value = 1.5 });
return list;
}
}
Sincerely
Ivano