Polar chartView SelectedPointChanged

2 posts, 0 answers
  1. ANTON
    ANTON avatar
    5 posts
    Member since:
    Apr 2016

    Posted 20 Dec 2016 Link to this post

    How to make it to catch ChartViewSelectedChanged event? Seems to work for other chart types such as cartesian or pie..

    public Form1()
    {
        InitializeComponent();
     
        radChartView1.Controllers.Add(new ChartSelectionController());
        radChartView1.SelectionMode = ChartSelectionMode.MultipleDataPoints;
        radChartView1.SelectedPointChanged += new ChartViewSelectedChangedEventHandler(OnChartSelectedPointChanged);
    }
     
    private void OnChartSelectedPointChanged(object sender, ChartViewSelectedPointChangedEventArgs e)
    {
        PolarDataPoint pt = e.NewSelectedPoint as PolarDataPoint;
        if (pt == null) return;
        System.Diagnostics.Debug.WriteLine(" angle = " + pt.Angle + " value = " + pt.Value);
    }
  2. Dimitar
    Admin
    Dimitar avatar
    2907 posts

    Posted 21 Dec 2016 Link to this post

    Hello Anton,

    Thank you for writing.

    It appears that there is an issue with the HitTest method in the series. I have logged the issue in our  Feedback Portal. I have added a vote for it on your behalf as well. You can track its progress, subscribe for status changes and add your comment to it here. I have also updated your Telerik Points.

    To workaround this you need to create a custom renderer and draw part:
    private void RadChartView1_CreateRenderer(object sender, ChartViewCreateRendererEventArgs e)
    {
        e.Renderer = new MyPolarRenderer(e.Area as PolarArea);
    }
     
    class MyPolarRenderer : PolarRenderer
    {
        public MyPolarRenderer(PolarArea area) : base(area)
        { }
     
        public override DataPoint HitTest(int x, int y)
        {
            for (int i = 0; i < this.DrawParts.Count; i++)
            {
                DataPoint dataPoint = this.DrawParts[i].HitTest(new Point(x, y));
                if (dataPoint != null)
                {
                    return dataPoint;
                }
            }
     
            return base.HitTest(x, y);
        }
        protected override void Initialize()
        {
            base.Initialize();
            for (int i = 0; i < this.DrawParts.Count; i++)
            {
                PolarPointSeriesDrawPart linePart = this.DrawParts[i] as PolarPointSeriesDrawPart;
                if (linePart != null)
                {
                    this.DrawParts[i] = new MyDrawpart((PolarPointSeries)linePart.Element, this);
                }
            }
        }
     
    }
    class MyDrawpart : PolarPointSeriesDrawPart
    {
        public MyDrawpart(PolarPointSeries series, IChartRenderer renderer) : base(series, renderer)
        { }
        public override DataPoint HitTest(Point location)
        {
            if (this.Element.PointSize.Width == 0 || this.Element.PointSize.Height == 0)
            {
                return null;
            }
     
            for (int i = 0; i < this.Element.DataPoints.Count; i++)
            {
                RadRect slot = this.Element.DataPoints[i].LayoutSlot;
                float pointHalfWidth = this.Element.PointSize.Width / 2;
                float pointHalfHeight = this.Element.PointSize.Height / 2;
     
                RectangleF dataPointBounds = new RectangleF((float)(slot.X - pointHalfWidth), (float)(slot.Y - pointHalfHeight), this.Element.PointSize.Width, this.Element.PointSize.Height);
     
                if (dataPointBounds.Contains(location.X, location.Y))
                {
                    return this.Element.DataPoints[i];
                }
            }
     
            return base.HitTest(location);
        }
    }

    Should you have any other questions do not hesitate to ask.

    Regards,
    Dimitar
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top