public class DataMarkerConverter : IValueConverter
{ public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var groupedData = new List<object>(); var groupedXData = new List<object>(); if (value == null) return value; if (value is List<Object>) { var groupedSegment = value as List<object>; for (int i = 0; i < groupedSegment.Count; i++) { groupedData.Add((groupedSegment[i] as Model).YValue); groupedXData.Add((groupedSegment[i] as Model).XValue); } return string.Format("{0} : {1} \n {2} : {3} \n {4} : {5}", groupedXData[0], groupedData[0], groupedXData[1], groupedData[1], groupedXData[2], groupedData[2]); } else { return string.Format("{0} : {1}", (value as Model).XValue, (value as Model).YValue); } } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { return value; } } |
protected override void OnSelectionChanged(Native.ChartSelectionEvent chartSelectionEvent)
{ base.OnSelectionChanged(chartSelectionEvent); ViewModel chartBindingContext = FormsChart.BindingContext as ViewModel; chartBindingContext.GroupedYValues = new ObservableCollection<Model>(); var segments = chartSelectionEvent.SelectedSeries.Segments; if (chartSelectionEvent.SelectedDataPointIndex == -1) { chartBindingContext.GroupedYValues.Clear(); return; } Native.PieSegment selectedSegment = segments[chartSelectionEvent.SelectedDataPointIndex] as Native.PieSegment; if (chartSelectionEvent.SelectedDataPointIndex == segments.Count - 1) { PropertyInfo dataPointInfo = typeof(Native.CircularSeries).GetProperty("GroupedData", BindingFlags.NonPublic | BindingFlags.Instance); List<object> groupedDataPoints = dataPointInfo.GetValue(chartSelectionEvent.SelectedSeries, null) as List<object>; for (int i = 0; i < groupedDataPoints.Count; i++) { chartBindingContext.GroupedYValues.Add(new Model((groupedDataPoints[i] as Model).XValue, (groupedDataPoints[i] as Model).YValue)); } } else { int selectedDataPointIndex = 0; var itemsource = chartSelectionEvent.SelectedSeries.ItemsSource; foreach (Model item in itemsource) { if ((item as Model).YValue == selectedSegment.YValue) { selectedDataPointIndex = (itemsource as ObservableCollection<Model>).IndexOf(item); break; } } chartBindingContext.GroupedYValues.Add(new Model((itemsource as ObservableCollection<Model>)[selectedDataPointIndex].XValue, selectedSegment.YValue)); } if (ListView != null) { ListView.ItemsSource = null; ListView.ItemsSource = chartBindingContext.GroupedYValues; } } |
public override void DidDataPointSelect(SFChartSelectionInfo selectionInfo)
{ base.DidDataPointSelect(selectionInfo); ViewModel chartBindingContext = FormsChart.BindingContext as ViewModel; chartBindingContext.GroupedYValues = new ObservableCollection<Model>(); var segments = selectionInfo.SelectedSeries.Segments; if (selectionInfo.SelectedDataPointIndex == -1) { chartBindingContext.GroupedYValues.Clear(); return; } SFPieSegment selectedSegment = segments[selectionInfo.SelectedDataPointIndex] as SFPieSegment; if (selectionInfo.SelectedDataPointIndex == segments.Count - 1) { PropertyInfo dataPointInfo = typeof(SFCircularSeries).GetProperty("GroupedData", BindingFlags.NonPublic | BindingFlags.Instance); List<object> groupedDataPoints = dataPointInfo.GetValue(selectionInfo.SelectedSeries, null) as List<object>; for (int i = 0; i < groupedDataPoints.Count; i++) { chartBindingContext.GroupedYValues.Add(new Model((groupedDataPoints[i] as Model).XValue, (groupedDataPoints[i] as Model).YValue)); } } else { int selectedDataPointIndex = 0; var itemsource = selectionInfo.SelectedSeries.ItemsSource; foreach (Model item in itemsource) { if ((item as Model).YValue == selectedSegment.YValue) { selectedDataPointIndex = (itemsource as ObservableCollection<Model>).IndexOf(item); break; } } chartBindingContext.GroupedYValues.Add(new Model((itemsource as ObservableCollection<Model>)[selectedDataPointIndex].XValue, selectedSegment.YValue)); } if (ListView != null) { ListView.ItemsSource = null; ListView.ItemsSource = chartBindingContext.GroupedYValues; } } |