1

Why the following code doesn't create the pie chart? How can I show the values expressed in percentage?

string[] seriesArray1 = new string[dataGridView1.Rows.Count];
double[] pointsArray1 = new double[dataGridView1.Rows.Count];

for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
   seriesArray1[i] = dataGridView1.Rows[i].Cells[0].Value.ToString();
   pointsArray1[i] = Convert.ToDouble(dataGridView1.Rows[i].Cells[1].Value);
}

chart1.Titles.Add("Probability");

for (int i = 0; i < seriesArray1.Length; i++)
{
   Series series = chart1.Series.Add(seriesArray1[i]);
   series.ChartType = SeriesChartType.Pie;
   series.IsValueShownAsLabel = true;
   series.Points.Add(pointsArray1[i]);
}
user3105160
  • 307
  • 1
  • 4
  • 13
  • Check http://stackoverflow.com/questions/1494252/making-a-graphic-pie-chart-in-c-sharp , also to display in a percent, you can do the math. Number/however long or try. – rguarascia.ts May 25 '14 at 03:02
  • This answer is wrong. It's not a duplicate because here I use the Chart component. – user3105160 May 25 '14 at 05:39
  • What about [How to set chart type to pie](http://stackoverflow.com/questions/14181902/how-to-set-chart-type-to-pie)? The first sentence seems to apply to your code: __You are adding multiple Series, {each with one Point.} As a result the charting control only displays the first Series. I believe what you are wanting to do is adding multiple points to a single Series.__ – TaW May 25 '14 at 06:36
  • Ok. I understand what you want to tell me, but does anyone know how to solve the problem with this code? Do you know tell me which part of the code is wrong? – user3105160 May 25 '14 at 09:21

0 Answers0