Ejemplo n.º 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;
        }
        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;
            }
        }