<chart:SfChart x:Name="chart" HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand">
….
<chart:FastScatterSeries ItemsSource="{Binding Data}"
XBindingPath="XValue"
YBindingPath="YValue"
ScatterWidth="10" ScatterHeight="10"
EnableAntiAliasing="False">
</chart:FastScatterSeries>
<chart:SfChart.ColorModel>
<chart:ChartColorModel Palette="Custom"
CustomGradientColors="{Binding GradientColors}">
</chart:ChartColorModel>
</chart:SfChart.ColorModel>
…
</chart:SfChart> |
GradientColors = new ChartGradientColorCollection()
{
new ChartGradientColor()
{
StartPoint = new Point(0.5, 1) , EndPoint = new Point(0.5,0),
GradientStops = new ChartGradientStopCollection()
{
new ChartGradientStop(){Offset = 0.30f, Color = Color.Green},
new ChartGradientStop(){Offset = 0.30f, Color = Color.Yellow},
new ChartGradientStop(){Offset = 0.50f, Color = Color.Yellow},
new ChartGradientStop(){Offset = 0.50f, Color = Color.Orange},
new ChartGradientStop(){Offset = 0.65f, Color = Color.Orange},
new ChartGradientStop(){Offset = 0.65f, Color = Color.Red},
}
}
}; |
public class ViewModel
{
….
public Action BeginDataUpdate;
public Action EndDataUpdate;
}
public partial class MainPage : ContentPage
{
ViewModel viewModel;
….
public MainPage()
{
InitializeComponent();
viewModel = new ViewModel();
this.BindingContext = viewModel;
viewModel.BeginDataUpdate = () => chart.SuspendSeriesNotification();
viewModel.EndDataUpdate = () => chart.ResumeSeriesNotification();
}
….
public async void LoadData()
{
await Task.Delay(500);
//dynamic change data using suspend and resume
Device.BeginInvokeOnMainThread(() =>
{
//chart.SuspendSeriesNotification() is called when using below code.
viewModel.BeginDataUpdate();
for (int i = 0; k < 128; k++)
{
//Add Data
}
//chart.ResumeSeriesNotification() is called when using below code.
viewModel.EndDataUpdate();
});
….
}
} |