Smartie Posted July 27, 2009 Report Share Posted July 27, 2009 Hey, 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) http://mysupport.softwarefx.com/help/supporttool/DownloadFile.aspx?FID=a9e4d15c-d038-4d6a-831e-dd4752ee78dc&InLine=true Quote Link to comment Share on other sites More sharing options...
juanZ Posted July 27, 2009 Report Share Posted July 27, 2009 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. Quote Link to comment Share on other sites More sharing options...
Smartie Posted July 28, 2009 Author Report Share Posted July 28, 2009 How do you know how many points there are from chart properties, the chart.points does not seem to know. Quote Link to comment Share on other sites More sharing options...
juanZ Posted July 28, 2009 Report Share Posted July 28, 2009 Hi Once datapoints has been assigned, you can access them with int myPointCount = chart1.Data.Points Quote Link to comment Share on other sites More sharing options...
Smartie Posted July 28, 2009 Author Report Share Posted July 28, 2009 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? Thanks 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 Next Quote Link to comment Share on other sites More sharing options...
juanZ Posted July 28, 2009 Report Share Posted July 28, 2009 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.