This is a migrated thread and some comments may be shown as answers.

Managing Chart Items

1 Answer 88 Views
Chart
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Chris Thierry
Top achievements
Rank 1
Chris Thierry asked on 04 May 2011, 10:01 PM
Hi,

    Is there any way of managing items in a PieChart? for example I want to show in my chart products and percentages. Is the percentage is less than 10%, I will create an item "Other". Every product under 10% it will be in this item "Other". I can say 20 or 30 percent...I want also to define this value. In this way I can show always the same qty of items and add the "Other" item according to this logic.

Can I do this using Chart Telerik RadControl?
Thank you.

    

1 Answer, 1 is accepted

Sort by
0
Tsvetie
Telerik team
answered on 10 May 2011, 12:24 PM
Hello Chris Thierry,
RadChart for Silverlight does not support this feature out of the box. You can, however, achieve the described result using one the the following approaches:
  • Construct your data source in such a way, so that all items with value less than 10% are added to an "Other" item.
  • Use the DataBound event of the chart to remove all items with YValue less than 10% and add them to a new "Other" item. For example:
    void RadChart1_DataBound(object sender, ChartDataBoundEventArgs e)
    {
        DataSeries series = RadChart1.DefaultView.ChartArea.DataSeries[0];
     
        double sum = 0d;
        foreach (DataPoint point in series)
        {
            sum += point.YValue;
        }
     
        DataPoint[] seriesItems = new DataPoint[series.Count];
        ((Collection<DataPoint>)series).CopyTo(seriesItems, 0);
     
        double otherDataPointValue = 0d;
        for (var i = 0; i < seriesItems.Length; i++)
        {
            DataPoint dataPoint = seriesItems[i];
            if (dataPoint.YValue / sum < 0.1d)
            {
                otherDataPointValue += dataPoint.YValue;
                series.Remove(dataPoint);
            }
        }
     
        DataPoint otherDataPoint = new DataPoint();
        otherDataPoint.YValue = otherDataPointValue;
        otherDataPoint.LegendLabel = "Other";
     
        series.Add(otherDataPoint);
    }

Regards,
Tsvetie
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Chart
Asked by
Chris Thierry
Top achievements
Rank 1
Answers by
Tsvetie
Telerik team
Share this question
or