예제 #1
0
        private void MChart_ChartTapped(object sender, C1TappedEventArgs e)
        {
            C1Point          point = e.GetPosition(mChart);
            ChartHitTestInfo info  = mChart.HitTest(point);
            // display hitTestInfo for each touch event
            string displayText = string.Empty;

            if (info != null)
            {
                displayText = chartElement + (info.ChartElement == null ? chartElementNone : info.ChartElement.ToString());
                if (info.Item != null)
                {
                    displayText += "\n" + seriesName + info.Series.Name + "\n" + pointIndex + info.PointIndex;
                    ChartPoint data = (ChartPoint)info.Item;

                    displayText += "\nX : " + data.Count;
                    if (info.Series.Name.Equals("sin(x)"))
                    {
                        displayText += " sin(x) : " + data.Sine;
                    }
                    else
                    {
                        displayText += " cos(x) : " + data.Cosine;
                    }
                }
            }
            else
            {
                displayText = "Well, this is not happening..";
            }
            mHitTestInfo.Text = displayText;
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            // Perform any additional setup after loading the view, typically from a nib.
            chart          = new FlexChart();
            chart.BindingX = "Name";
            chart.Series.Add(new ChartSeries()
            {
                SeriesName = "Sales", Binding = "Sales,Sales"
            });
            chart.Series.Add(new ChartSeries()
            {
                SeriesName = "Expenses", Binding = "Expenses,Expenses"
            });
            chart.Series.Add(new ChartSeries()
            {
                SeriesName = "Downloads", Binding = "Downloads,Downloads"
            });
            chart.ItemsSource = SalesData.GetSalesDataList();
            this.Add(chart);
            chart.Palette        = Palette.Cocoa;
            chart.Stacking       = ChartStackingType.Stacked;
            chart.LegendPosition = ChartPositionType.Bottom;

            MyTooltip t = new MyTooltip();

            t.Frame               = new CGRect(0, 0, 100, 50);
            t.BackgroundColor     = new UIColor(1.0f, 1.0f, 0.792f, 1.0f);
            chart.ToolTip         = t;
            chart.ToolTipLoading += (object sender, ChartTooltipLoadingEventArgs args) =>
            {
                ChartHitTestInfo e = args.HitTestInfo;
                if (e.Distance < 2 && e.PointIndex >= 0)
                {
                    double left = e.Point.X, top = e.Point.Y - t.Frame.Height, width = t.Frame.Width, height = t.Frame.Height;
                    double screenWidth = UIScreen.MainScreen.Bounds.Size.Width;
                    double margin      = 5;
                    if (left + width > screenWidth)
                    {
                        left = screenWidth - width - margin;
                    }
                    t.Frame = new CGRect(left, top, width, height);
                    t.UpdateContent(e);
                    t.IsOpen = true;
                }
                else
                {
                    t.IsOpen = false;
                }
            };
        }
        private void Sunburst_Tapped(object sender, C1.Android.Core.C1TappedEventArgs e)
        {
            C1Point          p           = e.GetPosition(sunburst);
            ChartHitTestInfo hitTestInfo = this.sunburst.HitTest(p);

            if (_view != null)
            {
                _view.Visibility = ViewStates.Invisible;
            }
            if (hitTestInfo == null || hitTestInfo.Item == null)
            {
                return;
            }

            if (hitTestInfo.Item is IChartModel)
            {
                View view = ((IChartModel)hitTestInfo.Item).GetUserView(this);

                _view = view;

                Rect myViewRect = new Rect();
                sunburst.GetGlobalVisibleRect(myViewRect);
                double length = myViewRect.Width() < myViewRect.Height() ? myViewRect.Width() : myViewRect.Height();
                length = length * sunburst.InnerRadius / 1.2; // 1.2 is proper size between 1 and 1.414(Math.Sqrt(2));

                int x = (int)(myViewRect.CenterX() - length / 2);
                int y = (int)(myViewRect.CenterY() - length);

                if (view.Parent != null)
                {
                    ((ViewGroup)view.Parent).RemoveView(view);
                }
                if (view.Parent == null)
                {
                    ViewGroup.LayoutParams para = new ViewGroup.LayoutParams((int)length, (int)length);
                    sunburst.AddView(view, para);
                }
                _view.SetX((int)(x + sunburst.TranslationX));
                _view.SetY((int)(y + sunburst.TranslationY));
                _view.ScaleX = (float)sunburst.Scale;
                _view.ScaleY = (float)sunburst.Scale;

                _view.Visibility = ViewStates.Visible;
                _x     = x;
                _y     = y;
                _width = _height = length;
            }
        }
예제 #4
0
        private void Sunburst_Tapped(object sender, C1.Xamarin.Forms.Core.C1TappedEventArgs e)
        {
            Point            p           = e.GetPosition(sunburst);
            ChartHitTestInfo hitTestInfo = this.sunburst.HitTest(p);

            if (hitTestInfo == null || hitTestInfo.Item == null)
            {
                return;
            }
            _item = ((IChartModel)hitTestInfo.Item);

            if (_view != null && _view.Parent != null)
            {
                sunburst.Children.Remove(_view);
            }

            if (hitTestInfo.Item is IChartModel)
            {
                _view = ((IChartModel)hitTestInfo.Item).GetUserView(fontSizeRate);
                _view.BackgroundColor = Color.Transparent;
                this.sunburst.Children.Add(_view);
                this.sunburst.RaiseChild(_view);

                _view.Layout(new Rectangle(_x - _width * sunburst.Scale / 2, _y - _height * sunburst.Scale / 2, _width * sunburst.Scale, _height * sunburst.Scale));

                if (_item is Periodic.Group && Periodic.Group.layout != null)
                {
                    ((Periodic.Group)_item).SetFontSize(fontSizeRate * (float)sunburst.Scale);
                }
                if (_item is Periodic.SubGroup && Periodic.SubGroup.layout != null)
                {
                    ((Periodic.SubGroup)_item).SetFontSize(fontSizeRate * (float)sunburst.Scale);
                }
                if (_item is Periodic.Element && Periodic.Element.layout != null)
                {
                    ((Periodic.Element)_item).SetFontSize(fontSizeRate * (float)sunburst.Scale);
                }
                if (_view != null)
                {
                    C1Sunburst sun = (C1Sunburst)sender;
                    _view.TranslationX = sun.TranslationX;
                    _view.TranslationY = sun.TranslationY;
                }
            }
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Create your application here
            SetContentView(Resource.Layout.activity_custom_tooltips);

            var toolbar = FindViewById <Toolbar>(Resource.Id.toolbar);

            SetSupportActionBar(toolbar);
            SupportActionBar.Title = GetString(Resource.String.customTooltips);
            SupportActionBar.SetDisplayHomeAsUpEnabled(true);
            SupportActionBar.SetHomeButtonEnabled(true);

            // initializing widget
            mChart = this.FindViewById <FlexChart>(Resource.Id.flexchart);
            Chartinitialization.InitialDefaultChart(mChart, ChartPoint.GetList());
            mChart.Stacking       = ChartStackingType.Stacked;
            mChart.Palette        = Palette.Cocoa;
            mChart.LegendPosition = ChartPositionType.Bottom;

            MyToolTip t = new MyToolTip(mChart, ApplicationContext);

            FrameLayout.LayoutParams l = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent);
            mChart.ToolTip         = t;
            mChart.ToolTipLoading += (object sender, ChartTooltipLoadingEventArgs args) =>
            {
                ChartHitTestInfo e = args.HitTestInfo;
                if (e.Distance < 2 && e.PointIndex >= 0)
                {
                    t.Point = new C1Point(e.Point.X, e.Point.Y);
                    t.UpdateContent(e);
                    t.IsOpen = true;
                }
                else
                {
                    t.IsOpen = false;
                }
            };
        }
예제 #6
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            // Perform any additional setup after loading the view, typically from a nib.
            chart          = new FlexChart();
            chart.BindingX = "Name";
            chart.Series.Add(new ChartSeries()
            {
                SeriesName = "Sales", Binding = "Sales,Sales"
            });
            chart.Series.Add(new ChartSeries()
            {
                SeriesName = "Expenses", Binding = "Expenses,Expenses"
            });
            chart.Series.Add(new ChartSeries()
            {
                SeriesName = "Downloads", Binding = "Downloads,Downloads"
            });
            chart.ItemsSource = SalesData.GetSalesDataList();
            this.Add(chart);
            chart.Palette        = Palette.Cocoa;
            chart.Stacking       = ChartStackingType.Stacked;
            chart.LegendPosition = ChartPositionType.Bottom;

            MyTooltip t = new MyTooltip();

            t.Frame           = new CGRect(0, 0, 100, 50);
            t.BackgroundColor = new UIColor(1.0f, 1.0f, 0.792f, 1.0f);

            chart.ToolTipLoading += (object sender, ChartTooltipLoadingEventArgs args) =>
            {
                ChartHitTestInfo e = args.HitTestInfo;
                if (e.Distance < 2 && e.PointIndex >= 0)
                {
                    t.UpdateContent(e);
                }
                args.view = t;
            };
        }
        private void Sunburst_Tapped(object sender, C1TappedEventArgs e)
        {
            CGPoint          p           = e.GetPosition(sunburst);
            ChartHitTestInfo hitTestInfo = this.sunburst.HitTest(p);

            if (hitTestInfo == null || hitTestInfo.Item == null)
            {
                popup.Hidden = true;
                return;
            }

            if (hitTestInfo.Item is IChartModel)
            {
                UIView view = ((IChartModel)hitTestInfo.Item).GetUserView(popup.Frame);
                view.Frame            = new CGRect(0, 0, popup.Frame.Width, popup.Frame.Height);
                popup.BackgroundColor = UIColor.Clear;
                foreach (UIView v in popup)
                {
                    v.RemoveFromSuperview();
                }
                popup.AddSubview(view);
                popup.Hidden = false;
            }
        }
예제 #8
0
        public void UpdateContent(ChartHitTestInfo hitTestInfo)
        {
            if (label == null && imageView == null)
            {
                label           = new UILabel(new CGRect(this.Bounds.Size.Width / 4, 0, this.Bounds.Size.Width * 3 / 4, this.Bounds.Size.Height));
                label.TextColor = UIColor.Black;
                label.Lines     = 3;
                label.Text      = string.Format("{0} \n\n {1:C2}", hitTestInfo.Series.Name, hitTestInfo.Y);
                label.Font      = label.Font.WithSize(11);

                image     = new UIImage("Images/" + SalesData.GetCountries()[hitTestInfo.PointIndex]);
                imageView = new UIImageView(image);
                this.AddSubview(imageView);
                this.AddSubview(label);
            }
            else
            {
                image           = new UIImage("Images/" + SalesData.GetCountries()[hitTestInfo.PointIndex]);
                imageView.Image = image;
                label.Text      = string.Format("{0} \n\n {1:C2}", hitTestInfo.Series.Name, hitTestInfo.Y);
                imageView.SetNeedsLayout();
                label.SetNeedsLayout();
            }
        }
 public void UpdateContent(ChartHitTestInfo hitTestInfo)
 {
     mFlag.SetImageResource(Resources.GetIdentifier(hitTestInfo.X.ToString().ToLower(CultureInfo.CurrentUICulture), "drawable", mParentPackage));
     mTitle.Text   = hitTestInfo.Series.Name;
     mContent.Text = hitTestInfo.X.ToString() + " " + hitTestInfo.Y.ToString();
 }