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(); } }
void InitPerformanceGraph() { foreach (var chart in chartContent.Subviews) { chart.RemoveFromSuperview(); } chartContent.LayoutIfNeeded(); pData = GetPerformance(); if (pData == null) { return; } mPChart = new FlexChart(); mPChart.Frame = new CGRect(0, 0, chartContent.Frame.Width, chartContent.Frame.Height); chartContent.AddSubview(mPChart); mPChart.Palette = XuniPalettes.Modern; mPChart.BackgroundColor = UIColor.Clear; mPChart.ChartType = ChartType.SplineArea; mPChart.BindingX = pData.categoryField; mPChart.IsAnimated = false; mPChart.ItemsSource = pData.GetSalesDataList(); mPChart.SymbolSize = 3; mPChart.Legend.Position = Position.None; mPChart.Tooltip.IsVisible = false; mPChart.AxisX.LabelsVisible = false; mPChart.AxisX.MajorTickWidth = 0; mPChart.AxisX.LineWidth = 0.5f; mPChart.AxisY.LabelsVisible = false; mPChart.AxisY.LineColor = UIColor.Orange.ColorWithAlpha(ALPHA_AXIS); mPChart.AxisY.MajorTickWidth = 0; mPChart.AxisY.MajorGridVisible = false; mPChart.AxisY.LabelsVisible = false; mPChart.AxisY.LineWidth = 2; for (int i = 0; i < pData.valueAxes.Count; i++) { var axis = pData.valueAxes[i]; Axis cAxis = new Axis(i % 2 == 0 ? Position.Left : Position.Right, mPChart); cAxis.AxisName = axis.id; cAxis.LineColor = FromHexString(axis.axisColor); cAxis.MajorTickWidth = 0; cAxis.MajorGridVisible = false; cAxis.LabelsVisible = false; cAxis.AxisLineVisible = false; mPChart.AxesArray.Add(cAxis); } foreach (var series in pData.graphs) { Series cSeries = new Series(mPChart, series.valueField, series.title); cSeries.AxisYname = series.valueAxis; UIColor sColor = FromHexString(series.lineColor); switch (series.valueField) { case "tsb": symTSB.BackgroundColor = sColor; break; case "atl": symATL.BackgroundColor = sColor; break; case "ctl": symCTL.BackgroundColor = sColor; break; case "dayliTss": symDailyLoad.BackgroundColor = sColor; break; case "dayliIf": symDailyIF.BackgroundColor = sColor; break; } if (series.lineAlpha.Equals(0)) { cSeries.ChartType = ChartType.Scatter; cSeries.SymbolColor = sColor; cSeries.Color = sColor; } else { cSeries.BorderWidth = 1; cSeries.BorderColor = sColor; cSeries.Color = sColor; cSeries.Opacity = ALPHA_FILL; } mPChart.Series.Add(cSeries); } mPChart.ItemsSource = pData.GetSalesDataList(); if (pData.TodayIndex() != -1) { var start = new XuniPoint(pData.TodayPosition() * mPChart.AxisX.ActualDataMax, mPChart.AxisY.ActualDataMax); var end = new XuniPoint(pData.TodayPosition() * mPChart.AxisX.ActualDataMax, mPChart.AxisY.ActualDataMin); XuniChartLineAnnotation today = new XuniChartLineAnnotation(mPChart) { IsVisible = true, Attachment = XuniChartAnnotationAttachment.DataCoordinate, Start = start, End = end, LineWidth = 3, TooltipText = "Future planned performance", Color = UIColor.Black, }; mPChart.Annotations.Add(today); } var annoFocused = new XuniChartRectangleAnnotation(mPChart) { IsVisible = false, Position = XuniChartAnnotationPosition.Center, Attachment = XuniChartAnnotationAttachment.DataCoordinate, Width = 2, Height = mPChart.AxisY.ActualDataMax, BorderWidth = 0, Text = DateTime.Now.ToString(), TextColor = UIColor.White, Color = UIColor.White, }; mPChart.Annotations.Add(annoFocused); #region custom line marker MyMarkerView view = new MyMarkerView(mPChart.LineMarker); view.MarkerRender = new MyMarkerRender(view, txtTSB, txtATL, txtCTL, txtDailyTSS, txtDailyIF); mPChart.LineMarker.Content = view; mPChart.LineMarker.IsVisible = true; mPChart.LineMarker.Alignment = XuniChartMarkerAlignment.BottomRight; mPChart.LineMarker.Lines = XuniChartMarkerLines.Vertical; mPChart.LineMarker.Interaction = XuniChartMarkerInteraction.Move; mPChart.LineMarker.DragContent = false; mPChart.LineMarker.SeriesIndex = -1; mPChart.LineMarker.VerticalLineColor = UIColor.White; mPChart.LineMarker.VerticalPosition = 10; mPChart.AddSubview(view); #endregion mPChart.ZoomMode = ZoomMode.Disabled; mPChart.AxisX.Scale = 1; zoomSlider.LowerValueChanged += HanelerGraphZoomChanged; zoomSlider.UpperValueChanged += HanelerGraphZoomChanged; zoomSlider.LowerValue = 0; zoomSlider.UpperValue = pData.dataProvider.Count; zoomSlider.MinimumValue = 0; zoomSlider.MaximumValue = pData.dataProvider.Count; zoomSlider.MinimumRange = 1; }