<chart:SfChart.Series>
<chart:FastLineSeries x:Name="series1" Color="Blue" ItemsSource="{Binding LineSeriesData}" XBindingPath="Date" YBindingPath="Value" Label="Actual">
</chart:FastLineSeries>
<local:FastLineSeriesExt x:Name="series2" Color="Blue" DataSource="{Binding LineSeriesData}" XBindingPath="Date" YBindingPath="Value" Label="Future">
</local:FastLineSeriesExt>
</chart:SfChart.Series> |
series2.StrokeRegion = new DateTime(2006, 01, 01);
series1.StrokeDashArray = new double[] { 5, 3 }; |
public class FastLineSeriesExt : FastLineSeries
{
/// <summary>
/// Gets or sets the data source to the chart. This is a bindable property.
/// </summary>
public static readonly BindableProperty DataSourceProperty =
BindableProperty.Create("DataSource", typeof(IEnumerable), typeof(FastLineSeriesExt), null, BindingMode.Default, null, OnDataSourceChanged);
/// <summary>
/// Gets or sets the Stroke started region. This is a bindable property.
/// </summary>
public static readonly BindableProperty StrokeRegionProperty =
BindableProperty.Create("StrokeRegion", typeof(DateTime?), typeof(FastLineSeriesExt), null, BindingMode.Default, null,OnStrokeRegionChanged);
public IEnumerable DataSource
{
get { return (IEnumerable)GetValue(DataSourceProperty); }
set { SetValue(DataSourceProperty, value); }
}
public DateTime? StrokeRegion
{
get { return (DateTime?)GetValue(StrokeRegionProperty); }
set { SetValue(StrokeRegionProperty, value); }
}
private static void OnDataSourceChanged(BindableObject bindable, object oldValue, object newValue)
{
var fastLineSeries = bindable as FastLineSeriesExt;
SetItemSource(fastLineSeries);
}
private static void OnStrokeRegionChanged(BindableObject bindable, object oldValue, object newValue)
{
var fastLineSeries = bindable as FastLineSeriesExt;
SetItemSource(fastLineSeries);
}
private static void SetItemSource(FastLineSeriesExt fastLineSeries)
{
if (fastLineSeries == null || fastLineSeries.DataSource == null)
return;
var data = fastLineSeries.DataSource as ObservableCollection<Model>;
fastLineSeries.ItemsSource = data?.Where(a => a.Date <= fastLineSeries.StrokeRegion).ToList();
}
} |