Jump to content
Software FX Community

Looping Through Pie Chart Points


Recommended Posts


I need to be able to loop through the points of a chart so I can set the colour of a pie charts slice depending on the text for that point. I cannot find a way to actually loop through them does anyone know how to do this?

We are using Chart FX 7 (7.0.3306.26568)


Link to comment
Share on other sites

 Hi, please try the following snippet. I choose random colors, but you can define your owns.


  int points = 3;
  chart1.Data.Series = 1;
  chart1.Data.Points = points;
  chart1.Data[0, 0] = 30;
  chart1.Data[0, 1] = 50;
  chart1.Data[0, 2] = 20;
  chart1.Data.Labels[0] = "Internet Explorer";
  chart1.Data.Labels[1] = "Netscape";
  chart1.Data.Labels[2] = "Other";
  chart1.Gallery = Gallery.Pie;

  Random r = new Random();
  for (int i = 0; i < points; i++)
  chart1.Points.Color = Color.FromArgb(r.Next(255), r.Next(255), r.Next(255));


Hope This helps.

Link to comment
Share on other sites

Hey juan,

Thanks for the reply.

I have tried what you said but I am finding the points text property is nothing. So I am unable to check it to see what colour that point should be.

Any ideas?


For lIndex As Integer = 0 To pChart.Data.Points

  Select Case pChart.Points(lIndex).Text

  Case "Always"
  pChart.Points(lIndex).Color = Drawing.Color.Blue
  Case "Mostly"
  pChart.Points(lIndex).Color = Drawing.Color.Green
  Case "Sometimes"
  pChart.Points(lIndex).Color = Drawing.Color.Orange
  Case "Never"
  pChart.Points(lIndex).Color = Drawing.Color.Red

  Case "Not satisfied"
  pChart.Points(lIndex).Color = Drawing.Color.Red
  Case "Average"
  pChart.Points(lIndex).Color = Drawing.Color.Orange
  Case "Good"
  pChart.Points(lIndex).Color = Drawing.Color.LightGreen
  Case "Very Good"
  pChart.Points(lIndex).Color = Drawing.Color.DarkGreen
  Case "Excellent"
  pChart.Points(lIndex).Color = Drawing.Color.Blue

  End Select


Link to comment
Share on other sites

 In the sample I posted, the values of the points are not defined in the text property of the points, they are in the Labels collection. Like this: chart1.Data.Labels[0] = "Firefox"; . The index of the chart1.Data.Labels[0] will correspond to the datapoint value. So, on your Case statement, you can use the chart1.Data.Labels[0] instead of the Points.Text.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...