// << path-geometry-set-line-geometry // >> path-gettingstarted-custom-geometry internal RadPathGeometry CreateArc() { var geometry = new RadPathGeometry(); RadPathFigure figure = new RadPathFigure(); figure.StartPoint = new Point(0.5, 0.5); // >> path-geometry-arc-segment RadArcSegment segmentA = new RadArcSegment(); segmentA.Center = new Point(0.5, 0.5); segmentA.Size = new Size(1, 1); segmentA.StartAngle = 315; segmentA.SweepAngle = 270; // << path-geometry-arc-segment figure.Segments.Add(segmentA); RadArcSegment segmentB = new RadArcSegment(); segmentB.Center = new Point(0.5, 0.5); segmentB.Size = new Size(1 - 0.1, 1 - 0.1); segmentB.StartAngle = 315 + 270; segmentB.SweepAngle = -270; figure.Segments.Add(segmentB); geometry.Figures.Add(figure); return(geometry); }
public PathGeometry() { InitializeComponent(); // >> path-geometry-customline-segment RadPathFigure customLine = new RadPathFigure(); customLine.StartPoint = new Point(0.8, 0.1); customLine.Segments.Add(new RadLineSegment(new Point(0.1, 0.8))); customLine.Segments.Add(new RadArcSegment() { Center = new Point(0.125, 0.825), StartAngle = 135, SweepAngle = 180, Size = new Size(0.070710678, 0.070710678) }); customLine.Segments.Add(new RadLineSegment(new Point(0.85, 0.15))); customLine.Segments.Add(new RadArcSegment() { Center = new Point(0.825, 0.125), StartAngle = 315, SweepAngle = 180, Size = new Size(0.070710678, 0.070710678) }); RadPathGeometry geometry = new RadPathGeometry(); geometry.Figures.Add(customLine); customLinePath.Geometry = geometry; // << path-geometry-customline-segment }
public PathGettingStartedCSharp() { // >> path-gettingstarted-starpath-code var mainGrid = new Grid() { ColumnSpacing = 20, RowSpacing = 10 }; mainGrid.RowDefinitions.Add(new RowDefinition() { Height = 200 }); mainGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Star }); mainGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Star }); var starPath = new RadPath() { Geometry = Geometries.Star, StrokeThickness = 0, Fill = new RadSolidColorBrush(Color.FromHex("FFC325")) }; mainGrid.Children.Add(starPath); // << path-gettingstarted-starpath-code // >> path-gettingstarted-custompath-code var arcPath = new RadPath() { StrokeThickness = 4, Stroke = new RadSolidColorBrush(Color.FromHex("2EC262")) }; RadPathFigure arc = new RadPathFigure(); arc.StartPoint = new Point(0.85, 0.85); arc.Segments.Add(new RadArcSegment() { Center = new Point(0.5, 0.5), Size = new Size(1, 1), StartAngle = 315, SweepAngle = 270 }); RadPathGeometry geometry = new RadPathGeometry(); geometry.Figures.Add(arc); arcPath.Geometry = geometry; mainGrid.Children.Add(arcPath); // << path-gettingstarted-custompath-code Grid.SetColumn(arcPath, 1); Content = mainGrid; }
// >> path-geometry-set-line-geometry internal RadPathGeometry CreateLineGeometry() { // >> path-geometry-line-segment RadPathFigure line = new RadPathFigure(); line.StartPoint = new Point(0.8, 0.1); line.Segments.Add(new RadLineSegment(new Point(0.1, 0.8))); // << path-geometry-line-segment line.Segments.Add(new RadArcSegment() { Center = new Point(0.125, 0.825), StartAngle = 135, SweepAngle = 180, Size = new Size(0.070710678, 0.070710678) }); line.Segments.Add(new RadLineSegment(new Point(0.85, 0.15))); line.Segments.Add(new RadArcSegment() { Center = new Point(0.825, 0.125), StartAngle = 315, SweepAngle = 180, Size = new Size(0.070710678, 0.070710678) }); RadPathGeometry geometry = new RadPathGeometry(); geometry.Figures.Add(line); return(geometry); }
private static Grid GeneratePieChart(IList <ChartDataPoint> dataPoints, List <Color> colors, bool showLegend = true) { // Root container to hold the chart and any legend var container = new Grid(); container.RowDefinitions.Add(new RowDefinition { Height = new GridLength(3, GridUnitType.Star) }); container.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }); // ***** Part 1 - PIE SERIES GENERATION ***** // // Sum up all the values to be displayed var totalValue = dataPoints.Sum(d => d.Value); // Variable to keep track of where each slice ended. double currentPosition = 0; // Iterate over the data points to create slices. for (int i = 0; i < dataPoints.Count; i++) { // Determine the percentage of the whole the slice uses. double slicePercentage = dataPoints[i].Value / totalValue; // Calculate the sweep using that percentage double sweep = slicePercentage * 360; // Create the ArcSegment using the calculated values. var segment = new RadArcSegment { Center = new Point(0.5, 0.5), Size = new Size(1, 1), StartAngle = currentPosition, SweepAngle = sweep, }; // Important - Calculate the last segment's ending angle in order to have a valid start angle for the next loop. currentPosition = currentPosition + sweep - 360; // Prepare the required PathFigure and add the ArcSegment var figure = new RadPathFigure { StartPoint = new Point(0.5, 0.5) }; figure.Segments.Add(segment); // Create the PathGeometry and add the PathFigure var geometry = new RadPathGeometry(); geometry.Figures.Add(figure); // Construct the RadPath // - Select a Fill color from the brushes parameter (important: use a modulus to wrap to the beginning) // - Use the Geometry created from the value var slice = new RadPath { Fill = new RadSolidColorBrush(colors[i % colors.Count]), Geometry = geometry, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center, WidthRequest = 100, HeightRequest = 100, Margin = new Thickness(0, 20, 0, 0) }; // This isn't necessary, but added for completion. Grid.SetRow(slice, 0); // Finally, add it to the container. container.Children.Add(slice); } // ***** Part 2 - LEGEND GENERATION ***** // if (showLegend) { var legendPanel = new StackLayout(); legendPanel.Orientation = StackOrientation.Horizontal; legendPanel.HorizontalOptions = LayoutOptions.Center; legendPanel.VerticalOptions = LayoutOptions.Center; legendPanel.Margin = new Thickness(0, 16, 0, 0); legendPanel.Spacing = 5; for (int i = 0; i < dataPoints.Count; i++) { // Use a RadBorder with only a bottom thickness and match the color to the slice var legendItem = new RadBorder(); legendItem.BorderColor = colors[i % colors.Count]; legendItem.BorderThickness = new Thickness(0, 0, 0, 2); // Create a Label for each data point and use the Title property var label = new Label { Text = dataPoints[i].Title, FontSize = 12, Margin = new Thickness(0, 0, 0, 2), TextColor = (Color)Application.Current.Resources["LightGrayTextColor"] }; legendItem.Content = label; legendPanel.Children.Add(legendItem); } Grid.SetRow(legendPanel, 1); container.Children.Add(legendPanel); } return(container); }
public SpeedometerCSharp() { RadRadialGauge gauge = new RadRadialGauge(); gauge.Axis = new GaugeLinearAxis { Minimum = 0, Maximum = 180, Step = 20, TickPosition = GaugeElementPosition.Start, LabelPosition = GaugeElementPosition.Start, StrokeThickness = 0, TickThickness = 2 }; RadPathFigure needleFigure = new RadPathFigure(); needleFigure.StartPoint = new Point(1, 0.5); needleFigure.Segments.Add(new RadLineSegment() { Point = new Point(0.55, 0.5) }); needleFigure.Segments.Add(new RadArcSegment() { Center = new Point(0.5, 0.5), Size = new Size(0.05, 0.05), StartAngle = 0, SweepAngle = 360 }); RadPathGeometry needleGeometry = new RadPathGeometry(); needleGeometry.Figures.Add(needleFigure); gauge.Indicators.Add(new GaugeNeedleIndicator() { Value = 60, Fill = Color.FromHex("037AFF"), Stroke = Color.FromHex("037AFF"), StrokeThickness = 3, Offset = 35, Shape = needleGeometry }); GaugeRangesDefinition gaugeRanges = new GaugeRangesDefinition() { StartThickness = 4, EndThickness = 4, Position = GaugeElementPosition.End }; gaugeRanges.Ranges.Add(new GaugeRange() { From = 0, To = 60, Color = Color.FromHex("646464") }); gaugeRanges.Ranges.Add(new GaugeRange() { From = 61, To = 120, Color = Color.FromHex("424242") }); gaugeRanges.Ranges.Add(new GaugeRange() { From = 121, To = 180, Color = Color.FromHex("DD0000") }); gauge.Ranges = gaugeRanges; Content = gauge; }