コード例 #1
0
        public Grid CreateChartContainer()
        {
            Grid chartGrid = new Grid();

            chartGrid.Background = new SolidColorBrush(Colors.White);

            RowDefinition row1 = new RowDefinition();

            row1.Height = new GridLength(0.7, GridUnitType.Star);
            RowDefinition row2 = new RowDefinition();

            row2.Height = new GridLength(9.3, GridUnitType.Star);
            chartGrid.RowDefinitions.Add(row1);
            chartGrid.RowDefinitions.Add(row2);

            ColumnDefinition column1 = new ColumnDefinition();

            column1.Width = new GridLength(8.2, GridUnitType.Star);
            ColumnDefinition column2 = new ColumnDefinition();

            column2.Width = new GridLength(0.2, GridUnitType.Star);
            ColumnDefinition column3 = new ColumnDefinition();

            column3.Width = new GridLength(1.6, GridUnitType.Star);
            chartGrid.ColumnDefinitions.Add(column1);
            chartGrid.ColumnDefinitions.Add(column2);
            chartGrid.ColumnDefinitions.Add(column3);
            chartGrid.Margin = new Thickness(10);

            TextBlock chartTitleTextBlock = new TextBlock
            {
                Text = chartTitle,
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment   = VerticalAlignment.Center,
                FontSize            = 16,
                FontWeight          = FontWeights.Bold
            };

            SetRow(chartTitleTextBlock, 0);
            SetColumn(chartTitleTextBlock, 0);
            SetColumnSpan(chartTitleTextBlock, 2);
            chartGrid.Children.Add(chartTitleTextBlock);

            SetRow(chart, 1);
            SetColumn(chart, 0);
            chartGrid.Children.Add(chart);

            RadLegend legendControl = new RadLegend();

            legendControl.Items = chart.LegendItems;
            SetRow(legendControl, 1);
            SetColumn(legendControl, 2);
            chartGrid.Children.Add(legendControl);

            return(chartGrid);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        private View CreateChart()
        {
            var container = new StackLayout();

            // >> chart-features-piechart-legend-definition-cs
            var chart = new RadPieChart
            {
                BindingContext = new ViewModel(),
                HeightRequest  = 300
            };
            // >> chart-features-piechart-legendtitlebinding-cs
            var series = new PieSeries
            {
                ValueBinding       = new PropertyNameDataPointBinding("Value"),
                DisplayName        = "Value",
                LegendTitleBinding = new PropertyNameDataPointBinding("Category")
            };

            // << chart-features-piechart-legendtitlebinding-cs
            series.SetBinding(ChartSeries.ItemsSourceProperty, new Binding("Data1"));
            chart.Series.Add(series);

            var legend = new RadLegend
            {
                LegendProvider      = chart,
                HeightRequest       = 200,
                LegendItemFontColor = Color.DarkGreen,
                LegendItemFontSize  = 20
            };

            // << chart-features-piechart-legend-definition-cs

            container.Children.Add(chart);
            container.Children.Add(legend);

            return(container);
        }