Exemplo n.º 1
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            LicenseManager.Key = License.Key;

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            // get chart from view
            chart = FindViewById <FlexChart>(Resource.Id.flexchart);

            // set title/footer
            chart.Header             = "FlexChart Sales";
            chart.Footer             = "GrapeCity Xuni";
            chart.Legend.BorderWidth = 1;
            chart.Legend.BorderColor = System.Drawing.Color.Gray.ToArgb();

            // set palette
            chart.SetPalette(Palettes.Modern);

            // bind X axis to display category names
            chart.BindingX = "Date";

            // create series with binding
            ChartSeries sales     = new ChartSeries(chart, "Sales", "Sales"); // new Series(chart, legend name, binding property)
            ChartSeries expenses  = new ChartSeries(chart, "Expenses", "Expenses");
            ChartSeries downloads = new ChartSeries(chart, "Downloads", "Downloads");

            downloads.ChartType = ChartType.Line;
            chart.Series.Add(sales);
            chart.Series.Add(expenses);
            chart.Series.Add(downloads);

            // set data source
            chart.ItemsSource = SalesData.GetSalesDataList();

            // configure default axes
            chart.AxisX.LabelAngle = 45;
            chart.AxisX.Format     = "d";
            chart.AxisY.Format     = "c0";
            chart.AxisY.Title      = "Dollars";

            // add second Y axis
            ChartAxis y2 = new ChartAxis(chart, ChartPositionType.Right);

            y2.Name             = "y2";
            y2.Format           = "n0";
            y2.MajorGridVisible = false;
            y2.MinorGridVisible = false;
            y2.LabelsVisible    = true;
            y2.Title            = "Downloads";
            chart.Axes.Add(y2);

            downloads.AxisY = "y2";

            // customize tooltip
            chart.Tooltip.Content = new MyTooltip(chart, chart.Context);

            // customize plot element
            chart.PlotElementLoading += chart_PlotElementLoading;

            // configure animation
            chart.LoadAnimation.AnimationMode = AnimationMode.Point;
        }
Exemplo n.º 2
0
        void InitPerformanceGraph(ReportGraphData pData)
        {
            this.pData = pData;

            mView.FindViewById <ScrollView>(Resource.Id.scrollView).ScrollTo(0, 0);
            if (pData == null)
            {
                return;
            }

            var chartContent = mView.FindViewById <LinearLayout>(Resource.Id.chartContent);

            chartContent.RemoveAllViews();

            try
            {
                mPChart = new FlexChart(this.Activity);
                LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);
                mPChart.LayoutParameters = params1;

                chartContent.AddView(mPChart);

                #region configure
                mPChart.SetPalette(Palettes.Modern);
                mPChart.SetBackgroundColor(Color.Transparent);
                mPChart.ChartType = ChartType.Splinearea;
                mPChart.BindingX  = pData.categoryField;
                mPChart.Animated  = false;
                #endregion

                #region regend
                mPChart.Legend.Position = ChartPositionType.None;
                #endregion

                #region axis
                mPChart.AxisX.LabelsVisible  = false;
                mPChart.AxisX.MajorTickWidth = 0;
                mPChart.AxisX.LineWidth      = 0.5f;

                mPChart.AxisY.LabelsVisible = false;
                mPChart.AxisY.LineColor     = new Color(Color.Orange.R, Color.Orange.G, Color.Orange.B, ALPHA_AXIS);
                mPChart.AxisY.LineWidth     = 2;

                for (int i = 0; i < pData.valueAxes.Count; i++)
                {
                    var       axis  = pData.valueAxes[i];
                    ChartAxis cAxis = new ChartAxis(mPChart, i % 2 == 0 ? ChartPositionType.Left : ChartPositionType.Right);
                    cAxis.Name             = axis.id;
                    cAxis.LineColor        = Color.ParseColor(axis.axisColor);
                    cAxis.MajorTickWidth   = 0;
                    cAxis.MajorGridVisible = false;
                    cAxis.LabelsVisible    = false;
                    cAxis.AxisLineVisible  = false;

                    mPChart.Axes.Add(cAxis);
                }
                #endregion

                #region series
                foreach (var series in pData.graphs)
                {
                    ChartSeries cSeries = new ChartSeries(mPChart, series.title, series.valueField);
                    cSeries.AxisY = series.valueAxis;

                    Color sColor = Color.ParseColor(series.lineColor);
                    var   sRGBA  = new Color(sColor.R, sColor.G, sColor.B, ALPHA_FILL);
                    cSeries.SetColor(new Java.Lang.Integer(sRGBA.ToArgb()));

                    ImageView imgSymbol = new ImageView(this.Context);
                    switch (series.valueField)
                    {
                    case "tsb":
                        imgSymbol = mView.FindViewById <ImageView>(Resource.Id.symTSB);
                        break;

                    case "atl":
                        imgSymbol = mView.FindViewById <ImageView>(Resource.Id.symATL);
                        break;

                    case "ctl":
                        imgSymbol = mView.FindViewById <ImageView>(Resource.Id.symCTL);
                        break;

                    case "dayliTss":
                        imgSymbol = mView.FindViewById <ImageView>(Resource.Id.symDailyTSS);
                        break;

                    case "dayliIf":
                        imgSymbol = mView.FindViewById <ImageView>(Resource.Id.symDailyIF);
                        break;
                    }
                    imgSymbol.SetBackgroundColor(sColor);

                    if (series.lineAlpha.Equals(0))
                    {
                        cSeries.ChartType   = ChartType.Scatter;
                        cSeries.SymbolSize  = new Java.Lang.Float(1.5f);
                        cSeries.SymbolColor = new Java.Lang.Integer(sColor);
                        cSeries.SetColor(new Java.Lang.Integer(sColor));
                    }
                    else
                    {
                        cSeries.BorderWidth = 0.5f;
                        cSeries.SetColor(new Java.Lang.Integer(sRGBA.ToArgb()));
                    }

                    mPChart.Series.Add(cSeries);
                }
                #endregion

                #region annotation
                if (pData.TodayIndex() != -1)
                {
                    ChartRectangleAnnotation today = new ChartRectangleAnnotation();
                    today.Attachment = ChartAnnotationAttachment.DataIndex;
                    today.PointIndex = pData.TodayIndex();
                    today.Width      = 3;
                    today.Height     = 10000;

                    today.Color       = Color.Black;
                    today.BorderWidth = 0;
                    today.FontSize    = 10;
                    today.TextColor   = Color.White.ToArgb();
                    today.TooltipText = "Future planned performance";
                    mPChart.Annotations.Add(today);
                }

                annoFocused.Attachment  = ChartAnnotationAttachment.DataIndex;
                annoFocused.PointIndex  = pData.TodayIndex();
                annoFocused.Width       = 1;
                annoFocused.Height      = 10000;
                annoFocused.Color       = Color.White;
                annoFocused.BorderWidth = 0;
                annoFocused.Visible     = false;
                annoFocused.FontSize    = 12;
                annoFocused.TextColor   = Color.White.ToArgb();
                mPChart.Annotations.Add(annoFocused);
                #endregion

                mPChart.ItemsSource = pData.GetSalesDataList();

                #region custom tooltip
                mPChart.Tooltip.Content = new MyTooltip(mPChart, this, pData, annoFocused);
                #endregion
                mPChart.ZoomMode    = ZoomMode.X;
                mPChart.AxisX.Scale = 1;
            }
            catch (Exception err)
            {
                Toast.MakeText(Activity, err.ToString(), ToastLength.Long).Show();
            }
        }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            LicenseManager.Key = License.Key;

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            // get chart from view
            chart = FindViewById<FlexChart>(Resource.Id.flexchart);
            
            // set title/footer
            chart.Header = "FlexChart Sales";
            chart.Footer = "GrapeCity Xuni";
            chart.Legend.BorderWidth = 1;
            chart.Legend.BorderColor = System.Drawing.Color.Gray.ToArgb();

            // set palette
            chart.SetPalette(Palettes.Modern);
            
            // bind X axis to display category names
            chart.BindingX = "Date";

            // create series with binding
            ChartSeries sales = new ChartSeries(chart, "Sales", "Sales"); // new Series(chart, legend name, binding property)
            ChartSeries expenses = new ChartSeries(chart, "Expenses", "Expenses");
            ChartSeries downloads = new ChartSeries(chart, "Downloads", "Downloads");

            downloads.ChartType = ChartType.Line;
            chart.Series.Add(sales);
            chart.Series.Add(expenses);
            chart.Series.Add(downloads);

            // set data source
            chart.ItemsSource = SalesData.GetSalesDataList();

            // configure default axes
            chart.AxisX.LabelAngle = 45;
            chart.AxisX.Format = "d";
            chart.AxisY.Format = "c0";
            chart.AxisY.Title = "Dollars";

            // add second Y axis
            ChartAxis y2 = new ChartAxis(chart, ChartPositionType.Right);
            y2.Name = "y2";
            y2.Format = "n0";
            y2.MajorGridVisible = false;
            y2.MinorGridVisible = false;
            y2.LabelsVisible = true;
            y2.Title = "Downloads";
            chart.Axes.Add(y2);

            downloads.AxisY = "y2";

            // customize tooltip
            chart.Tooltip.Content = new MyTooltip(chart, chart.Context);

            // customize plot element
            chart.PlotElementLoading += chart_PlotElementLoading;

            // configure animation
            chart.LoadAnimation.AnimationMode = AnimationMode.Point;

        }