ChartSelectionBehavior
概述
ChartSelectionBehavior负责选择、取消选择和报告数据点或序列的选择。换句话说,如果需要,选择行为可以针对数据点、序列或两者。
在R2 2018 SP版本中,RadChart的行为属性被替换为ChartBehaviors.行为属性被标记为过时,所以请使用ChartBehaviors代替。
特性
属性
- DataPointSelectionMode获取或设置ChartSelectionMode,该模式控制图表系列中数据点的选择行为。可用的值为:
- 没有一个
- 单
- 多个
- SeriesSelectionMode获取或设置ChartSelectionMode,该模式控制绘图区域内序列的选择行为。可用的值为:
- 没有一个
- 单
- 多个
- SelectedPoints:检索图表区域内所有系列中当前选定的所有点。
- SelectedSeries:检索当前选定的绘图区域内的所有系列实例。
方法
- ClearSelecton ()方法:删除图表中的当前选定项。
事件
- SelectionChanged事件:在做出选择时发生。
命令
ChartSelectionBehavior公开了对命令.
例子
下面是一个图表选择行为如何与命令一起工作的例子:
首先,创建所需的业务对象,例如:
公共类CategoricalData{公共对象类别{get;设置;}公共双值{get;设置;}}
然后创建一个ViewModel:
公共类ViewModel: NotifyPropertyChangedBase{私有int计数器= 0;private string displayCount;public ObservableCollection Data1 {get;设置;}公共ObservableCollection Data2 {get;设置;}公共iccommand IsSelectionChangedCommand {get;}公共ViewModel(){这个。Data1 = GetCategoricalData1();这一点。Data2 = GetCategoricalData2(); this.IsSelectionChangedCommand = new Command(this.IncreaseCount); } public int Counter { get { return this.counter; } set { this.counter = value; this.DisplayCount = $"Command executed {counter} times."; } } public string DisplayCount { get { return this.displayCount; } set { if (this.displayCount != value) { this.displayCount = value; this.OnPropertyChanged(); } } } private static ObservableCollection GetCategoricalData1() { var data = new ObservableCollection { new CategoricalData { Category = "Greenings", Value = 52 }, new CategoricalData { Category = "Perfecto", Value = 60 }, new CategoricalData { Category = "NearBy", Value = 77 }, new CategoricalData { Category = "Family", Value = 50 }, new CategoricalData { Category = "Fresh", Value = 56 }, }; return data; } private static ObservableCollection GetCategoricalData2() { var data = new ObservableCollection { new CategoricalData { Category = "Greenings", Value = 33 }, new CategoricalData { Category = "Perfecto", Value = 88 }, new CategoricalData { Category = "NearBy", Value = 61 }, new CategoricalData { Category = "Family", Value = 94 }, new CategoricalData { Category = "Fresh", Value = 72 }, }; return data; } private void IncreaseCount() { this.Counter++; } }
最后,使用下面的代码片段在XAML和c#中声明一个RadCartesianChart:
< ContentView。BindingContext> < telerikChart: RadCartesianChart。 < telerikChart: RadCartesianChart。 < telerikChart: RadCartesianChart。 < telerikChart: RadCartesianChart。ChartBehaviors>
var chart = new RadCartesianChart {BindingContext = new ViewModel(), PaletteName = PaletteNames。Light, SelectionPaletteName = palettename。LightSelected, HorizontalAxis = new CategoricalAxis() {LabelFitMode = AxisLabelFitMode。MultiLine,}, VerticalAxis = new NumericalAxis(), Series = {new BarSeries {ValueBinding = new PropertyNameDataPointBinding(“Value”),CategoryBinding = new PropertyNameDataPointBinding(“Category”),CombineMode = ChartSeriesCombineMode。Stack, StackGroupKey = 1, AllowSelect = true}, new BarSeries {ValueBinding = new PropertyNameDataPointBinding(“Value”),CategoryBinding = new PropertyNameDataPointBinding(“Category”),CombineMode = ChartSeriesCombineMode。Stack, StackGroupKey = 1, AllowSelect = true}}, ChartBehaviors = {new ChartSelectionBehavior {DataPointSelectionMode = ChartSelectionMode。Single, SeriesSelectionMode = ChartSelectionMode。无}}};chart.Series [0] .SetBinding (ChartSeries。ItemsSourceProperty Data1);chart.Series [1] .SetBinding (ChartSeries。ItemsSourceProperty”Data2”);
在哪里telerikChart命名空间如下:
xmlns: telerikChart = " clr-namespace: Telerik.XamarinForms.Chart;装配= Telerik.XamarinForms.Chart”
使用Telerik.XamarinForms.Chart;
以下是他们的选择:
的“图表/交互性”文件夹中可以找到一个选择示例SDK示例浏览器应用程序.