Profile Picture

How to get the value of single pie slice using code

Posted By Alan Hubbard 10 Years Ago
Author
Message
Alan Hubbard
Problem Posted 10 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: Forum Members
Last Active: 10 Years Ago
Posts: 5, Visits: 28
Hi
I have a requirement to show the top 10 pie slices and group all the rest together in one large slice. I need to add all the values for the large slice together, but I'm having difficulty accessing the values. Any tips/pointers are welcome. Thanks.
Here's my code:

double dLargeSliceValue = 0;
for (int i = pieSeries.GetDataPointCount(); i >= 0; i--)
  {
    dLargeSliceValue = dLargeSliceValue + pieSeries.Values[i].Value;
    if (i>9)
      { //group
        //add to value
        dLargeSliceValue = dLargeSliceValue + (double)pieSeries.Values[i]; /* this does not work */
        //remove initial slice
        pieSeries.RemoveDataPointAt(i);
      }
      else
      { //assign color
        pieSeries.FillStyles[i] = new NColorFillStyle(colorList[i]);
      }
  }
  // add a large slice
   NDataPoint dp = new NDataPoint(dLargeSliceValue, groupLabel);
   dp[DataPointValue.PieDetachment] = 1;
   pieSeries.AddDataPoint(dp);

Nevron Support
Posted 10 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: 1 days ago @ 1:38 AM
Posts: 3,054, Visits: 4,006
Hi Alan,

The most obvious problem with that code is that the index is incorrect:
int i = pieSeries.GetDataPointCount()
initializes i with an index which is outside the values bounds - it should be:
int i = pieSeries.GetDataPointCount() - 1

We tested with the following code:

   nChartControl1.Panels.Clear();

   NPieChart pieChart = new NPieChart();
   nChartControl1.Panels.Add(pieChart);


   NPieSeries pieSeries = new NPieSeries();
   pieChart.Series.Add(pieSeries);

   for (int i = 0; i < 20; i++)
   {
    pieSeries.Values.Add(i);
   }

   double dLargeSliceValue = 0.0;
   NChartPalette chartPalette = new NChartPalette(ChartPredefinedPalette.Autumn);
   List<Color> colorList = chartPalette.SeriesColors;

   for (int i = pieSeries.GetDataPointCount() - 1; i >= 0; i--)
   {
    if (i > 9)
    { //group
     //add to value
     dLargeSliceValue = dLargeSliceValue + (double)pieSeries.Values[i]; /* this does not work */
     //remove initial slice
     pieSeries.RemoveDataPointAt(i);
    }
    else
    { //assign color
     pieSeries.FillStyles[i] = new NColorFillStyle(colorList[i % colorList.Count]);
    }
   }
   // add a large slice
   NDataPoint dp = new NDataPoint(dLargeSliceValue, "Grouped");
   dp[DataPointValue.PieDetachment] = 1;
   pieSeries.AddDataPoint(dp);

and it was working properly. Let us know if you meet any problems or have any questions.



Best Regards,
Nevron Support Team



Alan Hubbard
Posted 10 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: Forum Members
Last Active: 10 Years Ago
Posts: 5, Visits: 28
Great, that worked, thanks!



Similar Topics


Reading This Topic