Пример #1
0
        public DateTimeAxis()
        {
            SFChart chart = new SFChart();

            chart.Title.Text = (NSString)"Food Production - 2017";

            chart.PrimaryAxis = new SFDateTimeAxis()
            {
                ZoomFactor = 0.1f, ZoomPosition = 0.6f, EdgeLabelsDrawingMode = SFChartAxisEdgeLabelsDrawingMode.Shift
            };
            chart.PrimaryAxis.LabelCreated += (sender, e) =>
            {
                var             date      = DateTime.Parse(e.AxisLabel.LabelContent.ToString());
                NSDateFormatter formatter = new NSDateFormatter();
                if (date.Month != month)
                {
                    SFAxisLabelStyle labelStyle = new SFAxisLabelStyle();
                    formatter.DateFormat      = new NSString("MMM-dd");
                    labelStyle.LabelFormatter = formatter;
                    labelStyle.Font           = UIFont.FromName("Helvetica-Bold", 9);
                    e.AxisLabel.LabelStyle    = labelStyle;
                    month = date.Month;
                }
                else
                {
                    SFAxisLabelStyle labelStyle = new SFAxisLabelStyle();
                    formatter.DateFormat      = new NSString("dd");
                    labelStyle.LabelFormatter = formatter;
                    e.AxisLabel.LabelStyle    = labelStyle;
                }
            };
            chart.PrimaryAxis.Title.Text = (NSString)"Production Across Years";

            chart.SecondaryAxis            = new SFNumericalAxis();
            chart.SecondaryAxis.Title.Text = (NSString)"Growth (In Metric Tons)";

            ChartViewModel dataModel = new ChartViewModel();

            SFFastLineSeries series = new SFFastLineSeries();

            series.ColorModel.Palette = SFChartColorPalette.Natural;
            series.ItemsSource        = dataModel.DateTimeAxisData;
            series.XBindingPath       = "XValue";
            series.YBindingPath       = "YValue";
            series.EnableTooltip      = true;
            chart.Series.Add(series);

            SFChartZoomPanBehavior zoomPan = new SFChartZoomPanBehavior();

            zoomPan.EnableSelectionZooming = false;
            zoomPan.ZoomMode = SFChartZoomMode.X;

            chart.Behaviors.Add(zoomPan);

            this.AddSubview(chart);
        }
        public BarChartView(string ChartTitle)
        {
            List<ChartData> chartData = new ChartDataRepository ().chartDataCollection;
            SFChartZoomPanBehavior zoomPanBehavior  = new SFChartZoomPanBehavior ();
            zoomPanBehavior.EnableSelectionZooming  = true;
            chart 									= new SFChart ();
            chart.Title.Text 						= new NSString (ChartTitle);
            chart.Title.Font 					    = UIFont.SystemFontOfSize (12, UIFontWeight.Bold);
            chart.Title.TextAlignment 			    = UITextAlignment.Center;
            SFCategoryAxis primary 					= new SFCategoryAxis ();
            primary.LabelPlacement					= SFChartLabelPlacement.BetweenTicks;
            primary.Title.Text 						= new NSString ("Security");
            chart.PrimaryAxis 						= primary;
            chart.PrimaryAxis.LabelsIntersectAction = SFChartAxisLabelsIntersectAction.MultipleRows;
            chart.SecondaryAxis 					= new SFNumericalAxis ();

            if (ChartTitle == "Top 5 Gains")
            {
                chart.SecondaryAxis.Title.Text = new NSString ("Gains");
                //chart.Title.Text = new NSString ("Top 5 Gains / Losses");
            };

            if (ChartTitle == "Top 5 Losers")
            {
                chart.SecondaryAxis.Title.Text = new NSString ("Losses");
                //chart.SecondaryAxis.Maximum				= new NSNumber (50);
                chart.SecondaryAxis.Interval = new NSNumber(50);
                //chart.Title.Text = new NSString ("");
            }

            if (ChartTitle == "P&L")
            {
                chart.SecondaryAxis.Title.Text = new NSString ("Gains/Losses");
                chart.Title.Text = new NSString("P&L by Securities");
            }

            BarChartRepository dataModel			= new BarChartRepository (chartData, ChartTitle);
            chart.DataSource 						= dataModel as SFChartDataSource;
            chart.Legend.Visible 					= false;
            chart.AddChartBehavior (zoomPanBehavior);
            this.control 							= chart;
        }