Completed
Last Updated: 10 Sep 2013 01:39 by ADMIN
ADMIN
Georgi I. Georgiev
Created on: 10 Sep 2013 01:39
Category: ChartView
Type: Bug Report
0
FIX. RadChartView - ChartTrackballController shows incorrect text
To reproduce:
this.chart.Controllers.Add(new ChartTrackballController());
this.chart.Dock = DockStyle.Fill;
this.chart.AreaType = ChartAreaType.Cartesian;
LineSeries lineSeries1 = new LineSeries();
lineSeries1.Name = "Line 1";

lineSeries1.DataPoints.Add(new CategoricalDataPoint(10, "1"));
lineSeries1.DataPoints.Add(new CategoricalDataPoint(4, "2"));
lineSeries1.DataPoints.Add(new CategoricalDataPoint(23, "3"));
lineSeries1.DataPoints.Add(new CategoricalDataPoint(11, "4"));
lineSeries1.DataPoints.Add(new CategoricalDataPoint(15, "5"));
lineSeries1.DataPoints.Add(new CategoricalDataPoint(10, "6"));
lineSeries1.DataPoints.Add(new CategoricalDataPoint(4, "7"));
lineSeries1.DataPoints.Add(new CategoricalDataPoint(7, "8"));
lineSeries1.DataPoints.Add(new CategoricalDataPoint(11, "9"));
lineSeries1.DataPoints.Add(new CategoricalDataPoint(15, "10"));
this.chart.Series.Add(lineSeries1);

LineSeries lineSeries2 = new LineSeries();
lineSeries2.Name = "Line 2";

lineSeries2.DataPoints.Add(new CategoricalDataPoint(6, "1"));
lineSeries2.DataPoints.Add(new CategoricalDataPoint(20, "2"));
lineSeries2.DataPoints.Add(new CategoricalDataPoint(7, "3"));
lineSeries2.DataPoints.Add(new CategoricalDataPoint(8, "4"));
lineSeries2.DataPoints.Add(new CategoricalDataPoint(4, "5"));
lineSeries2.DataPoints.Add(new CategoricalDataPoint(10, "6"));
lineSeries2.DataPoints.Add(new CategoricalDataPoint(24, "7"));
lineSeries2.DataPoints.Add(new CategoricalDataPoint(17, "8"));
lineSeries2.DataPoints.Add(new CategoricalDataPoint(18, "9"));
lineSeries2.DataPoints.Add(new CategoricalDataPoint(43, "10"));
this.chart.Series.Add(lineSeries2);
this.chart.ShowTrackBall = true;

For workaround, use this class:
public class MyTrackBallController : ChartTrackballController
{
    protected override string GetTrackballText(List<DataPointInfo> points)
    {
        StringBuilder result = new StringBuilder("<html>");

        SortedDictionary<Telerik.WinControls.UI.ChartSeries, List<DataPoint>> visiblePoints 
            = new SortedDictionary<Telerik.WinControls.UI.ChartSeries, List<DataPoint>>(new ChartSeriesComparer());
        
        foreach (DataPointInfo pointInfo in points)
        {
            if (visiblePoints.ContainsKey(pointInfo.Series))
            {
                visiblePoints[pointInfo.Series].Add(pointInfo.DataPoint);
            }
            else
            {
                visiblePoints.Add(pointInfo.Series, new List<DataPoint>() { pointInfo.DataPoint });
            }
        }
        
        int counter = 0;
        foreach (Telerik.WinControls.UI.ChartSeries series in visiblePoints.Keys)
        {
            for (int i = 0; i < visiblePoints[series].Count; i++)
            {
                Color pointColor = this.GetColorForDataPoint(series, visiblePoints[series][i]);
                string color = string.Format("{0},{1},{2},{3}", pointColor.A, pointColor.R, pointColor.G, pointColor.B);
                result.AppendFormat("<color={0}>{1}", color, this.GetPointText(visiblePoints[series][i]));
        
                if (i < visiblePoints[series].Count)
                {
                    result.Append(" ");
                }
            }
        
            counter++;
        
            if (counter < visiblePoints.Keys.Count)
            {
                result.Append("\n");
            }
        }
        
        result.Append("</html>");
        
        return result.ToString();
    }

    class ChartSeriesComparer : IComparer<Telerik.WinControls.UI.ChartSeries>
    {
        public int Compare(Telerik.WinControls.UI.ChartSeries x, Telerik.WinControls.UI.ChartSeries y)
        {
            if (!(x is IndicatorBase) && y is IndicatorBase)
            {
                return -1;
            }
            else if (x is IndicatorBase && !(y is IndicatorBase))
            {
                return 1;
            }

            if (x.Equals(y))
            {
                return 0;
            }

            return 1;
        }
    }

}
0 comments