Completed
Last Updated: 08 May 2014 10:06 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 01 May 2014 08:31
Category: ChartView
Type: Bug Report
0
FIX. RadChartView - ChartTooltipController does not always display the correct tooltip for ScatterDataPoints
To reproduce: use the following code snippet
public Form1()
{
    InitializeComponent();

    ScatterLineSeries scatterSeries = new ScatterLineSeries();
    scatterSeries.DataPoints.Add(new ScatterDataPoint(15, 19));
    scatterSeries.DataPoints.Add(new ScatterDataPoint(18, 10));
    scatterSeries.DataPoints.Add(new ScatterDataPoint(13, 15));
    scatterSeries.DataPoints.Add(new ScatterDataPoint(10, 8));
    scatterSeries.DataPoints.Add(new ScatterDataPoint(5, 2));
    scatterSeries.PointSize = new SizeF(8, 8);
    this.radChartView1.Series.Add(scatterSeries);

    ScatterLineSeries scatterSeries2 = new ScatterLineSeries();
    scatterSeries2.DataPoints.Add(new ScatterDataPoint(2, 24));
    scatterSeries2.DataPoints.Add(new ScatterDataPoint(7, 12));
    scatterSeries2.DataPoints.Add(new ScatterDataPoint(15, 10));
    scatterSeries2.DataPoints.Add(new ScatterDataPoint(18, 22));
    scatterSeries2.DataPoints.Add(new ScatterDataPoint(20, 20));
    scatterSeries2.Shape = new RoundRectShape(1);
    scatterSeries2.PointSize = new SizeF(8, 8);
    this.radChartView1.Series.Add(scatterSeries2);
    
    ChartTooltipController toolTipController = new ChartTooltipController();
   
    radChartView1.Controllers.Add(toolTipController); 
}

Workaround: use custom renderer

public Form1()
{
    InitializeComponent();

    this.radChartView1.CreateRenderer += radChartView1_CreateRenderer;
}
private void radChartView1_CreateRenderer(object sender, ChartViewCreateRendererEventArgs e)
{
    e.Renderer = new CustomCartesianRenderer(e.Area as CartesianArea);
}

public class CustomCartesianRenderer : CartesianRenderer
{
    public CustomCartesianRenderer(CartesianArea area) : base(area)
    {
    }
    
    protected override void Initialize()
    {
        base.Initialize();

        for (int i = 0; i < this.DrawParts.Count; i++)
        {
            ScatterSeriesDrawPart scatterPart = this.DrawParts[i] as ScatterSeriesDrawPart;
            if (scatterPart != null)
            {
                this.DrawParts[i] = new CustomScatterSeriesDrawPart((ScatterLineSeries)scatterPart.Element, this);
            }
        }
    }
}

public class CustomScatterSeriesDrawPart : ScatterLineSeriesDrawPart
{
    public CustomScatterSeriesDrawPart(ScatterLineSeries series, IChartRenderer renderer) 
        : base(series, renderer)
    {
    }

    public override DataPoint HitTest(Point location)
    {
        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 scatterBounds = new RectangleF((float)(this.OffsetX + slot.X - pointHalfWidth),
                (float)(this.OffsetY + slot.Y - pointHalfHeight), this.Element.PointSize.Width, this.Element.PointSize.Height);

            if (scatterBounds.Contains(location.X, location.Y))
            {
                return this.Element.DataPoints[i];
            }
        }

        return null;
    }
}
0 comments