private static void AnnotationsGroupChanged(DependencyObject target, DependencyPropertyChangedEventArgs args) { RadCartesianChart chart = target as RadCartesianChart; if (chart == null) { return; } string group = (string)args.NewValue; if (group != null && !attachedCharts.Contains(chart)) { attachedCharts.Add(chart); chart.MouseMove += Chart_MouseMove; chart.MouseLeave += Chart_MouseLeave; } else if (group == null) { chart.MouseMove -= Chart_MouseMove; attachedCharts.Remove(chart); chart.MouseLeave -= Chart_MouseLeave; if (lastMouseOveredChart == chart) { lastMouseOveredChart = null; } } }
private static void chart_MouseMove(object sender, System.Windows.Input.MouseEventArgs e) { RadCartesianChart chart = (RadCartesianChart)sender; if (!GetIsSelectionRectangleShown(chart)) { return; } var plotAreaClip = chart.PlotAreaClip; plotAreaClip.X += chart.PanOffset.X; plotAreaClip.Y += chart.PanOffset.Y; Point toPosition = e.GetPosition(chart); toPosition.X = Math.Max(plotAreaClip.X, toPosition.X); toPosition.X = Math.Min(toPosition.X, plotAreaClip.Right); toPosition.Y = Math.Max(plotAreaClip.Y, toPosition.Y); toPosition.Y = Math.Min(toPosition.Y, plotAreaClip.Bottom); SetToPosition(chart, toPosition); UpdateSelectionRectanglePositionAndSize(chart); // Instant selection - select items while dragging. //UpdateDataPointsInSelectionRectangle(chart); }
private static void Chart_MouseMove(object sender, System.Windows.Input.MouseEventArgs e) { RadCartesianChart chart = (RadCartesianChart)sender; lastMouseOveredChart = chart; string group = GetAnnotationsGroup(chart); object currentXCategory = GetCurrentXCategory(chart); Point position = e.GetPosition(chart); if (!chart.PlotAreaClip.Contains(position.X, position.Y)) { if (HidesAnnotationsOnMouseLeave && currentXCategory != null) { HideAnnotations(group); } return; } DataTuple tuple = chart.ConvertPointToData(position); object xCategory = tuple.FirstValue; if (object.Equals(xCategory, currentXCategory)) { return; } UpdateCharts(group, xCategory); }
private static void chart_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { RadCartesianChart chart = (RadCartesianChart)sender; Point fromPosition = e.GetPosition(chart); SetFromPosition(chart, fromPosition); SetToPosition(chart, fromPosition); var plotAreaClip = chart.PlotAreaClip; plotAreaClip.X += chart.PanOffset.X; plotAreaClip.Y += chart.PanOffset.Y; if (!plotAreaClip.Contains(fromPosition.X, fromPosition.Y)) { return; } chart.CaptureMouse(); Canvas adorner = Telerik.Windows.Controls.ChildrenOfTypeExtensions.ChildrenOfType <Canvas>(chart).First(c => c.Name == "adornerContainer"); Style style = GetSelectionRectangleStyle(chart); FrameworkElement selectionRectangle = BuildSelectionRectangle(style); adorner.Children.Add(selectionRectangle); UpdateSelectionRectanglePositionAndSize(chart); SetIsSelectionRectangleShown(chart, true); }
public StackAreaSeriesCSharp() { // >> chart-series-stackarea-csharp var chart = new RadCartesianChart { BindingContext = new SeriesCategoricalViewModel(), HorizontalAxis = new CategoricalAxis() { LabelFitMode = AxisLabelFitMode.MultiLine, PlotMode = AxisPlotMode.OnTicks }, VerticalAxis = new NumericalAxis(), Series = { new AreaSeries { ValueBinding = new PropertyNameDataPointBinding("Value"), CategoryBinding = new PropertyNameDataPointBinding("Category"), CombineMode = ChartSeriesCombineMode.Stack }, new AreaSeries { ValueBinding = new PropertyNameDataPointBinding("Value"), CategoryBinding = new PropertyNameDataPointBinding("Category"), CombineMode = ChartSeriesCombineMode.Stack } } }; chart.Series[0].SetBinding(ChartSeries.ItemsSourceProperty, "Data1"); chart.Series[1].SetBinding(ChartSeries.ItemsSourceProperty, "Data2"); // << chart-series-stackarea-csharp this.Content = chart; }
private static bool TryRunStackedBarsAnimtation(CartesianSeries series) { Canvas renderSurface = Telerik.Windows.Controls.ChildrenOfTypeExtensions.FindChildByType <Canvas>(series); List <FrameworkElement> bars = new List <FrameworkElement>(); foreach (FrameworkElement uiElement in renderSurface.Children) { Border bar = uiElement as Border; ContentPresenter cp = uiElement as ContentPresenter; if ((bar != null && (bar.DataContext is CategoricalDataPoint)) || (cp != null && cp.Content is CategoricalDataPoint)) { bars.Add(uiElement); } } Storyboard storyboard = new Storyboard(); RadCartesianChart chart = (RadCartesianChart)series.Chart; int initialDelay = (int)(BarAnimationDuration.TimeSpan.Milliseconds * chart.Series.IndexOf(series)); TimeSpan?beginTime = TimeSpan.FromMilliseconds(initialDelay); for (int i = 0; i < bars.Count; i++) { var animation = BuildStackedBarAnimation(bars[i], beginTime, BarAnimationDuration, series); storyboard.Children.Add(animation); beginTime = new TimeSpan(0, 0, 0, 0, initialDelay + (BarDelayInMilliseconds * (i + 1))); } return(Run(storyboard, series)); }
public ChartGridLinesCSharp() { // >> chart-customization-gridlines-csharp var chart = new RadCartesianChart { BindingContext = new ViewModel(), VerticalAxis = new NumericalAxis(), HorizontalAxis = new CategoricalAxis() { LabelFitMode = AxisLabelFitMode.MultiLine }, Series = { new BarSeries { ValueBinding = new PropertyNameDataPointBinding("Value"), CategoryBinding = new PropertyNameDataPointBinding("Category") } }, Grid = new CartesianChartGrid { StripLinesVisibility = GridLineVisibility.None, MajorLinesVisibility = GridLineVisibility.XY, MajorLineColor = Color.Gray, MajorLineThickness = 1 } }; chart.Series[0].SetBinding(ChartSeries.ItemsSourceProperty, "Data"); // << chart-customization-gridlines-csharp this.Content = chart; }
public SplineSeriesCSharp() { // >> chart-series-spline-csharp var chart = new RadCartesianChart { BindingContext = new ViewModel(), HorizontalAxis = new CategoricalAxis() { LabelFitMode = AxisLabelFitMode.MultiLine, PlotMode = AxisPlotMode.OnTicks }, VerticalAxis = new NumericalAxis(), Series = { new SplineSeries { ValueBinding = new PropertyNameDataPointBinding("Value"), CategoryBinding = new PropertyNameDataPointBinding("Category") } }, Grid = new CartesianChartGrid { MajorLinesVisibility = GridLineVisibility.XY, MajorXLineDashArray = new[] { 4.0, 2.0 }, MajorYLineDashArray = new[] { 4.0, 2.0 }, MajorLineColor = Color.FromHex("D3D3D3"), MajorLineThickness = 2 } }; chart.Series[0].SetBinding(ChartSeries.ItemsSourceProperty, "Data"); // << chart-series-spline-csharp this.Content = chart; }
public BarSeriesHorizontalCSharp() { // >> chart-series-barhorizontal-csharp var chart = new RadCartesianChart { BindingContext = new CategoricalDataViewModel(), VerticalAxis = new CategoricalAxis() { LabelFitMode = AxisLabelFitMode.MultiLine, }, HorizontalAxis = new NumericalAxis() { LabelFitMode = AxisLabelFitMode.MultiLine, }, Series = { new BarSeries { ValueBinding = new PropertyNameDataPointBinding("Value"), CategoryBinding = new PropertyNameDataPointBinding("Category") } } }; chart.Series[0].SetBinding(ChartSeries.ItemsSourceProperty, "Data"); // << chart-series-barhorizontal-csharp this.Content = chart; }
public ScatterAreaSeriesCSharp() { // >> chart-series-scatterarea-csharp var chart = new RadCartesianChart { BindingContext = new ViewModel(), HorizontalAxis = new NumericalAxis() { LabelFitMode = AxisLabelFitMode.MultiLine }, VerticalAxis = new NumericalAxis(), Series = { new ScatterAreaSeries { XValueBinding = new PropertyNameDataPointBinding("XData"), YValueBinding = new PropertyNameDataPointBinding("YData") } }, Grid = new CartesianChartGrid { MajorLinesVisibility = GridLineVisibility.Y, MajorYLineDashArray = new[] { 4.0, 2.0 }, MajorLineColor = Color.FromHex("D3D3D3"), MajorLineThickness = 2 } }; chart.Series[0].SetBinding(ChartSeries.ItemsSourceProperty, "Data"); // << chart-series-scatterarea-csharp this.Content = chart; }
public FinancialIndicatorsExampleCSharp() { // >> chart-series-financial-indicators-csharp var chart = new RadCartesianChart { BackgroundColor = Color.White, BindingContext = new ViewModel(), HorizontalAxis = new DateTimeContinuousAxis() { LabelFitMode = AxisLabelFitMode.Rotate, PlotMode = AxisPlotMode.BetweenTicks, MajorStepUnit = TimeInterval.Day, MajorStep = 2, LabelFormat = "dd/MM", LineColor = Color.FromHex("#A9A9A9") }, VerticalAxis = new NumericalAxis() { LineColor = Color.FromHex("#A9A9A9"), Maximum = 350, Minimum = 320, MajorTickBackgroundColor = Color.FromHex("#A9A9A9") }, Series = { new OhlcSeries { CategoryBinding = new PropertyNameDataPointBinding("Category"), OpenBinding = new PropertyNameDataPointBinding("Open"), HighBinding = new PropertyNameDataPointBinding("High"), LowBinding = new PropertyNameDataPointBinding("Low"), CloseBinding = new PropertyNameDataPointBinding("Close") }, new ExponentialMovingAverageIndicator { CategoryBinding = new PropertyNameDataPointBinding("Category"), ValueBinding = new PropertyNameDataPointBinding("Close"), Period = 7, Stroke = Color.DarkGreen, StrokeThickness = 1, DisplayName = "EMA 7days" }, new ExponentialMovingAverageIndicator { CategoryBinding = new PropertyNameDataPointBinding("Category"), ValueBinding = new PropertyNameDataPointBinding("Close"), Period = 14, Stroke = Color.DarkOrange, StrokeThickness = 1, DisplayName = "EMA 14days" } } }; chart.Series[0].SetBinding(ChartSeries.ItemsSourceProperty, "SeriesData"); chart.Series[1].SetBinding(ChartSeries.ItemsSourceProperty, "SeriesData"); chart.Series[2].SetBinding(ChartSeries.ItemsSourceProperty, "SeriesData"); // << chart-series-financial-indicators-csharp this.Content = chart; }
public ToolTipSeriesCSharp() { // >> chart-interactivity-tooltipseries-csharp var chart = new RadCartesianChart { BindingContext = new ViewModel(), HorizontalAxis = new CategoricalAxis() { LabelFitMode = AxisLabelFitMode.MultiLine, PlotMode = AxisPlotMode.OnTicks }, VerticalAxis = new NumericalAxis(), Series = { new LineSeries { ValueBinding = new PropertyNameDataPointBinding("Value"), CategoryBinding = new PropertyNameDataPointBinding("Category"), DisplayName = "Sales 1" }, }, ChartBehaviors = { new ChartTooltipBehavior { TriggerMode = ToolTipTriggerMode.Tap } } }; chart.Series[0].SetBinding(ChartSeries.ItemsSourceProperty, "Data"); // << chart-interactivity-tooltipseries-csharp this.Content = chart; }
private static RadCartesianChart CreateChart() { // >> chart-getting-started-csharp-chart var chart = new RadCartesianChart { HorizontalAxis = new CategoricalAxis(), VerticalAxis = new NumericalAxis(), BindingContext = new GettingStarted.ViewModel() }; var series = new BarSeries(); series.SetBinding(ChartSeries.ItemsSourceProperty, new Binding("Data")); series.ValueBinding = new PropertyNameDataPointBinding { PropertyName = "Value" }; series.CategoryBinding = new PropertyNameDataPointBinding { PropertyName = "Category" }; chart.Series.Add(series); // << chart-getting-started-csharp-chart return(chart); }
public void CreateSeries() { RadCartesianChart chart = this.RequestTimeLineChar as RadCartesianChart; chart.Series.Clear(); //指定建立五个序列 for (int i = 0; i < 5; i++) { CategoricalSeries series = null; if (chart == null)//若图表为null { return; } //创建指定类型的序列 series = new LineSeries() { Stroke = DefaultPalette.FillEntries.Brushes[i], StrokeThickness = 3, PointTemplate = chart.Resources["PointTemplate"] as DataTemplate }; series.CategoryBinding = new PropertyNameDataPointBinding("RequestTime"); series.ValueBinding = new PropertyNameDataPointBinding("ResponseTime"); series.SetBinding(ChartSeries.ItemsSourceProperty, new Binding() { Path = new PropertyPath("Infos.LineChartCollection[" + i + "]") }); series.ClipToPlotArea = false; //序列添加到图表 chart.Series.Add(series); } }
public FormatAxisLabels() { var chart = new RadCartesianChart { VerticalAxis = new NumericalAxis { LabelFormat = "C", MajorStep = 0.5, Minimum = -1, Maximum = 1 }, HorizontalAxis = new DateTimeContinuousAxis { LabelFormatter = new DateLabelFormatter(), LabelFitMode = AxisLabelFitMode.Rotate, MajorStepUnit = TimeInterval.Day, } }; var series = new LineSeries { ItemsSource = GetSource(), ValueBinding = new PropertyNameDataPointBinding("Value"), CategoryBinding = new PropertyNameDataPointBinding("Date") }; chart.Series.Add(series); this.Content = chart; }
public ScatterLineSeriesCSharp() { // >> chart-series-scatterline-csharp var chart = new RadCartesianChart { BindingContext = new SeriesNumericalViewModel(), HorizontalAxis = new NumericalAxis() { LabelFitMode = AxisLabelFitMode.MultiLine }, VerticalAxis = new NumericalAxis(), Series = { new ScatterLineSeries { XValueBinding = new PropertyNameDataPointBinding("XData"), YValueBinding = new PropertyNameDataPointBinding("YData") }, new ScatterLineSeries { XValueBinding = new PropertyNameDataPointBinding("XData"), YValueBinding = new PropertyNameDataPointBinding("YData") } } }; chart.Series[0].SetBinding(ChartSeries.ItemsSourceProperty, "Data1"); chart.Series[1].SetBinding(ChartSeries.ItemsSourceProperty, "Data2"); // << chart-series-scatterline-csharp this.Content = chart; }
public FormatAxisLabelsCSharp() { // >> chart-customization-formataxislabels-csharp var chart = new RadCartesianChart { BindingContext = new ViewModel(), VerticalAxis = new NumericalAxis { LabelFormat = "C", MajorStep = 0.5, Minimum = -1, Maximum = 1 }, HorizontalAxis = new DateTimeContinuousAxis { LabelFormatter = new DateLabelFormatter(), LabelFitMode = AxisLabelFitMode.Rotate, MajorStepUnit = TimeInterval.Day, }, Series = { new LineSeries { ValueBinding = new PropertyNameDataPointBinding("Value"), CategoryBinding = new PropertyNameDataPointBinding("Date") } } }; chart.Series[0].SetBinding(ChartSeries.ItemsSourceProperty, "Data"); // << chart-customization-formataxislabels-csharp this.Content = chart; }
private void Legend_MouseDown(object sender, MouseButtonEventArgs e) { Border brder = (Border)sender; //brder.BorderThickness = new Thickness(0, 0, 0, 1); LegendItem item = brder.DataContext as LegendItem; BarSeries series = item.Presenter as BarSeries; RadCartesianChart chart = series.Chart as RadCartesianChart; foreach (BarSeries s in chart.Series) { s.Visibility = Visibility.Collapsed; } series.Visibility = Visibility.Visible; foreach (Border br in FindVisualChildren <Border>(chartLegend)) { if (br.Name == "brdr") { br.BorderThickness = new Thickness(0, 0, 0, 0); } } brder.BorderThickness = new Thickness(0, 0, 0, 1.5); }
public static void DispatchRunAnimations(RadChartBase chart) { IEnumerable <ChartSeries> series = null; RadCartesianChart cartesianChart = chart as RadCartesianChart; if (cartesianChart != null) { series = cartesianChart.Series; } RadPieChart pieChart = chart as RadPieChart; if (pieChart != null) { series = pieChart.Series; } if (series.Any(s => (int)s.GetValue(ChartAnimationUtilities.RunningAnimationsCountProperty) > 0)) { return; } foreach (ChartSeries s in series) { DispatchRunSeriesAnimations(s); } }
private static void AnnotationsGroupChanged(DependencyObject target, DependencyPropertyChangedEventArgs args) { RadCartesianChart chart = target as RadCartesianChart; if (chart == null) { return; } string group = (string)args.NewValue; if (group != null && !attachedCharts.Contains(chart)) { attachedCharts.Add(chart); chart.MouseMove += Chart_MouseMove; chart.MouseLeave += Chart_MouseLeave; } else if (group == null) { chart.MouseMove -= Chart_MouseMove; attachedCharts.Remove(chart); chart.MouseLeave -= Chart_MouseLeave; if (lastMouseOveredChart == chart) { lastMouseOveredChart = null; } } }
public LeakageViewModel(RadCartesianChart radchart) { BeginDate = DateTime.Now.AddDays(-7); EndDate = DateTime.Now; InitAction(); InitEvent(); _radchart1 = radchart; _radchart1.Series.Clear(); var itemss = new ObservableCollection <LeakQueryoneItemViewModel>(); //var line = new LineSeries(); //for (var i = new DateTime(BeginDate.AddDays(-1).Year, BeginDate.AddDays(-1).Month, // BeginDate.AddDays(-1).Day, 12, 0, 0); // i < new DateTime(BeginDate.Year, BeginDate.Month, BeginDate.Day, 12, 0, 1); ) for (var i = new DateTime(BeginDate.Year, BeginDate.Month, BeginDate.Day, 12, 0, 0); i < new DateTime(EndDate.Year, EndDate.Month, EndDate.Day, 12, 0, 1);) { itemss.Add(new LeakQueryoneItemViewModel() { DateCreate = i, Value = 0 }); //line.DataPoints.Add(new CategoricalDataPoint() { Value = 0, Category = i }); //_radchart1.Series.Add(line); i = i.AddHours(2); } AddLines(itemss, new SolidColorBrush(Colors.White)); Step1 = 1; LeakId = 1600001; }
private static void OnTimerTick(RadCartesianChart chart) { CameraInfo cameraInfo = GetOrCreateCameraInfo(chart); double durationInSeconds = 1.5; Point targetOffset = new Point(100, -75); TimeSpan timeSpan = DateTime.Now - cameraInfo.initialAnimationDateTime; if (durationInSeconds < timeSpan.TotalSeconds) { cameraInfo.initialAnimationTimer.Stop(); cameraInfo.initialAnimationTimer = null; return; } double progress = timeSpan.TotalSeconds / durationInSeconds; EasingFunctionBase ease = new BackEase { EasingMode = EasingMode.EaseIn }; double easedProgress = ease.Ease(progress); double hOffset = easedProgress * targetOffset.X; ease = new CubicEase { EasingMode = EasingMode.EaseInOut }; easedProgress = ease.Ease(progress); double vOffset = easedProgress * targetOffset.Y; MoveCamera(chart, new Point(hOffset, vOffset)); }
public SelectionSeriesCSharp() { // >> chart-interactivity-selectionseries-csharp var chart = new RadCartesianChart { BindingContext = new ViewModel(), PaletteName = PaletteNames.Light, SelectionPaletteName = PaletteNames.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 } }, Behaviors = { new ChartSelectionBehavior { DataPointSelectionMode = ChartSelectionMode.Single, SeriesSelectionMode = ChartSelectionMode.None } }, Grid = new CartesianChartGrid { StripLinesVisibility = GridLineVisibility.Y, YStripeColor = Color.Transparent, YStripeAlternativeColor = Color.FromHex("1FA9A9A9"), MajorLinesVisibility = GridLineVisibility.Y, MajorYLineDashArray = new[] { 4.0, 2.0 }, MajorLineColor = Color.FromHex("D3D3D3"), MajorLineThickness = 2 } }; chart.Series[0].SetBinding(ChartSeries.ItemsSourceProperty, "Data1"); chart.Series[1].SetBinding(ChartSeries.ItemsSourceProperty, "Data2"); // << chart-interactivity-selectionseries-csharp this.Content = chart; }
public object Convert(object value, Type targetType, object parameter, string language) { BarSeries series = (value as DataPointInfo).Series as BarSeries; RadCartesianChart chart = series.Chart as RadCartesianChart; var dataPoint = (value as DataPointInfo).DataPoint; Border border = series.GetDataPointVisual(dataPoint) as Border; return(border.Background); }
private static void RemoveAnnotations(RadCartesianChart chart) { var toBeRemoved = chart.Annotations.Where(ann => object.Equals(ann.Tag, typeof(ChartUtilities))).ToList(); foreach (var ann in toBeRemoved) { chart.Annotations.Remove(ann); } }
public static void AddTriangularDistributionAnnotation(this RadCartesianChart chart, Vertex selectedVertex, EvidenceRow dataRow, string columnName) { var from = (double)dataRow["From"]; var to = (double)dataRow["To"]; var vertexEvidence = dataRow[columnName] as VertexEvidence; var fill1 = new LinearGradientBrush { StartPoint = new Point(0, 0), EndPoint = new Point(0, 1) }; fill1.GradientStops.Add(new GradientStop { Offset = 0, Color = Color.FromArgb(255, 218, 165, 32) }); fill1.GradientStops.Add(new GradientStop { Offset = 1, Color = Color.FromArgb(50, 218, 165, 32) }); chart.Annotations.Add(new CartesianMarkedZoneAnnotation { Fill = fill1, HorizontalFrom = @from, HorizontalTo = to, Stroke = new SolidColorBrush(Colors.Goldenrod), Tag = dataRow, VerticalFrom = vertexEvidence.Params[1], VerticalTo = vertexEvidence.Params[0], ZIndex = -200 }); var fill2 = new LinearGradientBrush { StartPoint = new Point(0, 0), EndPoint = new Point(0, 1) }; fill2.GradientStops.Add(new GradientStop { Offset = 0, Color = Color.FromArgb(0, 218, 165, 32) }); fill2.GradientStops.Add(new GradientStop { Offset = 1, Color = Color.FromArgb(255, 218, 165, 32) }); chart.Annotations.Add(new CartesianMarkedZoneAnnotation { Fill = fill2, HorizontalFrom = @from, HorizontalTo = to, Stroke = new SolidColorBrush(Colors.Goldenrod), Tag = dataRow, VerticalFrom = vertexEvidence.Params[2], VerticalTo = vertexEvidence.Params[1], ZIndex = -200 }); }
private static void Chart_LostMouseCapture(object sender, MouseEventArgs e) { RadCartesianChart chart = (RadCartesianChart)sender; CameraInfo cameraInfo = GetOrCreateCameraInfo(chart); if (cameraInfo.isMouseCaptured) { cameraInfo.isMouseCaptured = false; } }
private static void AddIntersectionPoint(RadCartesianChart chart, DataTemplate intersectionPointTemplate, CategoricalDataPoint dataPoint) { CartesianCustomAnnotation annotation = new CartesianCustomAnnotation(); annotation.ContentTemplate = intersectionPointTemplate; annotation.HorizontalValue = dataPoint.Category; annotation.VerticalValue = dataPoint.Value; annotation.Tag = typeof(ChartUtilities); chart.Annotations.Add(annotation); }
private static void Chart_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e) { RadCartesianChart chart = (RadCartesianChart)sender; if (HidesAnnotationsOnMouseLeave) { string group = GetAnnotationsGroup(chart); HideAnnotations(group); } }
private View CreateChart() { var container = new StackLayout(); // >> chart-features-cartesianchart-legend-definition-cs var chart = new RadCartesianChart { HorizontalAxis = new CategoricalAxis(), VerticalAxis = new NumericalAxis(), BindingContext = new ViewModel(), HeightRequest = 300 }; var seriesData1 = new LineSeries { CategoryBinding = new PropertyNameDataPointBinding("Category"), ValueBinding = new PropertyNameDataPointBinding("Value"), DisplayName = "Data1" }; seriesData1.SetBinding(ChartSeries.ItemsSourceProperty, new Binding("Data1")); chart.Series.Add(seriesData1); var seriesData2 = new LineSeries { CategoryBinding = new PropertyNameDataPointBinding("Category"), ValueBinding = new PropertyNameDataPointBinding("Value"), DisplayName = "Data2" }; seriesData2.SetBinding(ChartSeries.ItemsSourceProperty, new Binding("Data2")); chart.Series.Add(seriesData2); var seriesData3 = new LineSeries { CategoryBinding = new PropertyNameDataPointBinding("Category"), ValueBinding = new PropertyNameDataPointBinding("Value"), DisplayName = "Data3" }; seriesData3.SetBinding(ChartSeries.ItemsSourceProperty, new Binding("Data3")); chart.Series.Add(seriesData3); var legend = new RadLegend { LegendProvider = chart, HeightRequest = 200, LegendItemFontColor = Color.DarkGreen, Orientation = LegendOrientation.Horizontal }; // << chart-features-cartesianchart-legend-definition-cs container.Children.Add(chart); container.Children.Add(legend); return(container); }
private static void Chart_MouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e) { RadCartesianChart chart = (RadCartesianChart)sender; CameraInfo cameraInfo = GetOrCreateCameraInfo(chart); if (cameraInfo.isMouseCaptured) { chart.ReleaseMouseCapture(); cameraInfo.isMouseCaptured = false; } }
public MainPage() { InitializeComponent(); RadCartesianChart chart = new RadCartesianChart(); chart.HorizontalAxis = new CategoricalAxis(); chart.VerticalAxis = new LinearAxis() { Maximum = 100 }; LineSeries line = new LineSeries(); line.Stroke = new SolidColorBrush(Colors.Orange); line.StrokeThickness = 2; line.DataPoints.Add(new CategoricalDataPoint() { Value = 20 }); line.DataPoints.Add(new CategoricalDataPoint() { Value = 40 }); line.DataPoints.Add(new CategoricalDataPoint() { Value = 35 }); line.DataPoints.Add(new CategoricalDataPoint() { Value = 40 }); line.DataPoints.Add(new CategoricalDataPoint() { Value = 30 }); line.DataPoints.Add(new CategoricalDataPoint() { Value = 50 }); chart.Series.Add(line); chart.SetValue(Grid.ColumnProperty, 1); this.LayoutRoot.Children.Add(chart); }
private static void OnTimerTick(RadCartesianChart chart) { CameraInfo cameraInfo = GetOrCreateCameraInfo(chart); double durationInSeconds = 1.5; Point targetOffset = new Point(100, -75); TimeSpan timeSpan = DateTime.Now - cameraInfo.initialAnimationDateTime; if (durationInSeconds < timeSpan.TotalSeconds) { cameraInfo.initialAnimationTimer.Stop(); cameraInfo.initialAnimationTimer = null; return; } double progress = timeSpan.TotalSeconds / durationInSeconds; EasingFunctionBase ease = new BackEase { EasingMode = EasingMode.EaseIn }; double easedProgress = ease.Ease(progress); double hOffset = easedProgress * targetOffset.X; ease = new CubicEase { EasingMode = EasingMode.EaseInOut }; easedProgress = ease.Ease(progress); double vOffset = easedProgress * targetOffset.Y; MoveCamera(chart, new Point(hOffset, vOffset)); }
private static void AddIntersectionPoint(RadCartesianChart chart, DataTemplate intersectionPointTemplate, CategoricalDataPoint dataPoint) { CartesianCustomAnnotation annotation = new CartesianCustomAnnotation(); annotation.ContentTemplate = intersectionPointTemplate; annotation.HorizontalValue = dataPoint.Category; annotation.VerticalValue = dataPoint.Value; annotation.Tag = typeof(ChartUtilities); chart.Annotations.Add(annotation); }
private static void AddAnnotations(RadCartesianChart chart, object xCategory) { chart.Annotations.Add(new CartesianGridLineAnnotation { Axis = chart.HorizontalAxis, Value = xCategory, Tag = typeof(ChartUtilities) }); StackPanel dataPointsInfoPanel = new StackPanel(); foreach (CartesianSeries series in chart.Series) { CategoricalSeries categoricalSeries = series as CategoricalSeries; if (categoricalSeries == null) { continue; } var dataPoint = GetDataPoint(categoricalSeries.DataPoints, xCategory); if (dataPoint == null) { continue; } AddIntersectionPoint(chart, GetIntersectionPointTemplate(series), dataPoint); ContentPresenter cp = new ContentPresenter(); cp.ContentTemplate = GetDataPointTemplate(series); cp.Content = dataPoint; dataPointsInfoPanel.Children.Add(cp); } foreach (IndicatorBase indicator in chart.Indicators) { foreach (var dataPoint in GetDataPoints(indicator, xCategory)) { AddIntersectionPoint(chart, GetIntersectionPointTemplate(indicator), dataPoint); } } LinearAxis vAxis = (LinearAxis)chart.VerticalAxis; CartesianCustomAnnotation infoAnnotation = new CartesianCustomAnnotation(); infoAnnotation.Tag = typeof(ChartUtilities); infoAnnotation.HorizontalValue = xCategory; infoAnnotation.VerticalValue = vAxis.ActualRange.Maximum; infoAnnotation.Content = PrepareInfoContent(dataPointsInfoPanel); chart.Annotations.Add(infoAnnotation); }
private static void RemoveAnnotations(RadCartesianChart chart) { var toBeRemoved = chart.Annotations.Where(ann => object.Equals(ann.Tag, typeof(ChartUtilities))).ToList(); foreach (var ann in toBeRemoved) { chart.Annotations.Remove(ann); } }
private static void Chart_MouseMove(object sender, System.Windows.Input.MouseEventArgs e) { RadCartesianChart chart = (RadCartesianChart)sender; lastMouseOveredChart = chart; string group = GetAnnotationsGroup(chart); object currentXCategory = GetCurrentXCategory(chart); Point position = e.GetPosition(chart); if (!chart.PlotAreaClip.Contains(position.X, position.Y)) { if (HidesAnnotationsOnMouseLeave && currentXCategory != null) { HideAnnotations(group); } return; } DataTuple tuple = chart.ConvertPointToData(position); object xCategory = tuple.FirstValue; if (object.Equals(xCategory, currentXCategory)) { return; } UpdateCharts(group, xCategory); }
private static Point GetNewOffset(RadCartesianChart chart, Point pos) { CameraInfo cameraInfo = GetOrCreateCameraInfo(chart); Point pos1 = cameraInfo.mouseDownPosition; Point pos2 = pos; double hDelta = pos2.X - pos1.X; hDelta = hDelta / 10; double newHOffset = cameraInfo.mouseDownOffset.X + hDelta; newHOffset = Math.Max(Math.Min(newHOffset, MaxOffset), -MaxOffset); double vDelta = pos1.Y - pos2.Y; vDelta = vDelta / 10; double newVOffset = cameraInfo.mouseDownOffset.Y + vDelta; newVOffset = Math.Max(Math.Min(newVOffset, MaxOffset), 0); return new Point(newHOffset, newVOffset); }
private static void UpdateSelectionRectanglePositionAndSize(RadCartesianChart chart) { Point fromPosition = GetFromPosition(chart); Point toPosition = GetToPosition(chart); Rect rect = new Rect(fromPosition, toPosition); FrameworkElement selectionRectangle = Telerik.Windows.Controls.ChildrenOfTypeExtensions.ChildrenOfType<FrameworkElement>(chart).First(r => object.Equals(r.Tag, SelectionRectangleTag)); Canvas.SetLeft(selectionRectangle, rect.X); Canvas.SetTop(selectionRectangle, rect.Y); selectionRectangle.Width = rect.Width; selectionRectangle.Height = rect.Height; }
private void ParseXML( XDocument what, int i, RadCartesianChart targetChart, RadCustomHubTile rt1, RadCustomHubTile rt2, RadCustomHubTile rt3, TextBlock t1, TextBlock t2, TextBlock t3, // stats numbers TextBlock tb, // total info String sDate, String eDate, TextBlock tr1, // total info number TextBlock tr2, // total info date/time range int targetSeries // if it is basic or compare function ) { Debug.WriteLine("Processing..." + what); DataSource.getChartData()[i,targetSeries] = from query in what.Descendants("day") select new ChartDataPoint { Value = (double)query.Attribute("value"), Label = (string)query.Attribute("date") }; Debug.WriteLine("Setting DataContext of loaded data"); /* var mydate = new Windows.Globalization.DateTimeFormatting.DateTimeFormatter("month day"); var mydatepattern = mydate.Patterns[0]; sDate = String.Format(mydatepattern, DateTime.Parse(sDate)); eDate = String.Format(mydatepattern, DateTime.Parse(eDate)); */ if (targetSeries > 0) { // progressBar.Visibility = System.Windows.Visibility.Visible; rt1.IsFrozen = false; rt2.IsFrozen = false; rt3.IsFrozen = false; tb.Visibility = Visibility.Visible; tr2.Visibility = Visibility.Visible; tr2.Text = "(" + sDate + " - " + eDate + ")"; } else // reset compare chart { TextBlock[] totals = { info4Text1, info4Text2, info4Text3, info4Text4, info4Text5, info4Text6, info4Text7, info4Text8 }; if (i < 8) { totals[i].Visibility = Visibility.Collapsed; } targetChart.Series[1].ItemsSource = null; tr1.Visibility = Visibility.Visible; tr2.Visibility = Visibility.Collapsed; tr1.Text = "(" + sDate + " - " + eDate + ")"; rt1.IsFlipped = false; rt2.IsFlipped = false; rt3.IsFlipped = false; rt1.IsFrozen = true; rt2.IsFrozen = true; rt3.IsFrozen = true; } Debug.WriteLine("Setting DataContext targetSeries:" + targetSeries); if (targetSeries > 0) // if it's compare we have to fake time { var previousData = DataSource.getChartData()[i, 0]; ObservableCollection<ChartDataPoint> newData = new ObservableCollection<ChartDataPoint>(); IEnumerator<ChartDataPoint> enumerator = previousData.GetEnumerator() as System.Collections.Generic.IEnumerator<ChartDataPoint>; int p = 0; while (enumerator.MoveNext()) { ChartDataPoint c = enumerator.Current; Debug.WriteLine("Old Label:" + DataSource.getChartData()[i, 1].ElementAt<ChartDataPoint>(p).Label + " New Label:" + c.Label); ChartDataPoint n = new ChartDataPoint { Value = DataSource.getChartData()[i, 1].ElementAt<ChartDataPoint>(p).Value, Label = c.Label }; newData.Add(n); Debug.WriteLine("New label set:" + DataSource.getChartData()[i, 1].ElementAt<ChartDataPoint>(p).Label); p++; } DataSource.getChartData()[i, 1] = newData; } targetChart.Series[targetSeries].ItemsSource = DataSource.getChartData()[i, targetSeries]; targetChart.HorizontalAxis.LabelInterval = Util.getLabelIntervalByCount(DataSource.getChartData()[i, targetSeries].Count()); // count max,min,latest,total for display purposes double latest = 0, minim = 9999999999999, maxim = 0, totalCount = 0; IEnumerator<ChartDataPoint> Myenum = DataSource.getChartData()[i,targetSeries].GetEnumerator(); while (Myenum.MoveNext()) { ChartDataPoint oneValue = Myenum.Current; latest = oneValue.Value; minim = Math.Min(minim, oneValue.Value); maxim = Math.Max(maxim, oneValue.Value); totalCount = totalCount + oneValue.Value; } t1.Text = latest.ToString(); t2.Text = minim.ToString(); t3.Text = maxim.ToString(); switch (AppMetricsNames[i]) { case "MedianSessionLength": case "AvgSessionLength": tb.Text = "N/A"; // makes no sense for these metrics break; default: tb.Text = totalCount.ToString(); break; } tb.Visibility = Visibility.Visible; } // ParseXML
private static void UpdateDataPointsInSelectionRectangle(RadCartesianChart chart) { Point fromPosition = GetFromPosition(chart); fromPosition.X -= chart.PanOffset.X; fromPosition.Y -= chart.PanOffset.Y; Point toPosition = GetToPosition(chart); toPosition.X -= chart.PanOffset.X; toPosition.Y -= chart.PanOffset.Y; Rect rect = new Rect(fromPosition, toPosition); foreach (CategoricalSeries series in chart.Series) { foreach (CategoricalDataPoint dp in series.DataPoints) { RadPoint point = dp.LayoutSlot.Center; dp.IsSelected = rect.Contains(new Point(point.X, point.Y)); } } }
private static void MoveCamera(RadCartesianChart chart, Point position) { Point newOffset = GetNewOffset(chart, position); double angleX = Math.Atan(newOffset.X / newOffset.Y) * 180 / Math.PI; double angleY = Math.Atan(newOffset.Y / newOffset.X) * 180 / Math.PI; chart.Resources["hOffset"] = newOffset.X; chart.Resources["hOffsetNegated"] = -newOffset.X; chart.Resources["hOffsetHalf"] = newOffset.X / 2; chart.Resources["vOffset"] = newOffset.Y; chart.Resources["vOffsetNegated"] = -newOffset.Y; chart.Resources["vOffsetNegatedHalf"] = -newOffset.Y / 2; chart.Resources["chart25DAngleX"] = -angleX; chart.Resources["chart25DAngleY"] = -angleY; }
private static CameraInfo GetOrCreateCameraInfo(RadCartesianChart chart) { CameraInfo cameraInfo = (CameraInfo)chart.GetValue(CameraInfoProperty); if (cameraInfo == null) { cameraInfo = new CameraInfo(); chart.SetValue(CameraInfoProperty, cameraInfo); } return cameraInfo; }
public MainPage() { InitializeComponent(); BackgroundColor = Xamarin.Forms.Device.OnPlatform(Xamarin.Forms.Color.White, Xamarin.Forms.Color.White, Xamarin.Forms.Color.Transparent); var chart = new RadCartesianChart { HorizontalAxis = new Telerik.XamarinForms.Chart.CategoricalAxis() { LabelFitMode = AxisLabelFitMode.MultiLine, }, VerticalAxis = new Telerik.XamarinForms.Chart.NumericalAxis() { LabelFitMode = AxisLabelFitMode.MultiLine, RangeExtendDirection = NumericalAxisRangeExtendDirection.Both, MajorStep = 30, }, }; var series = new BarSeries(); chart.Series.Add(series); this.Content = chart; series.ValueBinding = new Telerik.XamarinForms.Chart.PropertyNameDataPointBinding { PropertyName = "Value" }; series.CategoryBinding = new Telerik.XamarinForms.Chart.PropertyNameDataPointBinding { PropertyName = "Category" }; series.ItemsSource = MainViewModel.GetCategoricalData(); var grid = new CartesianChartGrid(); grid.MajorLinesVisibility = GridLineVisibility.Y; grid.MajorYLineDashArray = Device.OnPlatform(null, new double[] { 4, 2 }, new double[] { 4, 2 }); grid.StripLinesVisibility = GridLineVisibility.Y; grid.YStripeColor = Color.FromRgba(99, 99, 99, 100); grid.YStripeAlternativeColor = Color.FromRgba(169, 169, 169, 31); grid.MajorLineColor = Color.FromRgb(211, 211, 211); grid.MajorLineThickness = Device.OnPlatform(0.5, 2, 2); chart.Grid = grid; var treshold = MainViewModel.GetCategoricalData().Average(c => c.Value); var startTreshold = treshold * 0.95; var endTreshold = treshold * 1.05; var lineAnnotation = new CartesianGridLineAnnotation() { Axis = chart.VerticalAxis, Value = treshold, Stroke = Color.FromRgb(255, 0, 0), StrokeThickness = Device.OnPlatform(0.5, 2, 2), DashArray = new double[] { 4, 2 }, }; var bandAnnotation = new CartesianPlotBandAnnotation() { Axis = chart.VerticalAxis, From = startTreshold, To = endTreshold, Fill = Color.FromRgba(255, 0, 0, 50), StrokeThickness = 2, Stroke = Color.Transparent, }; chart.Annotations.Add(bandAnnotation); chart.Annotations.Add(lineAnnotation); }