Link to home
Start Free TrialLog in
Avatar of spen_lang
spen_lang

asked on

VB NET Pie Chart Segment Colours

Hi,

Is it possible to set the colour of each segment of a oie chart in VB NET using the Chart control?

For example I have a pie chart that counts the names in a table, I would like Ted to be red and Fred to be green etc...

I have found out how to do it by index number:
series1.Points(0).Color = Color.Blue

but need something like this
series1.Points("Fred").Color = Color.Green
series1.Points("Ted").Color = Color.Red

Thanks, Greg
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of spen_lang
spen_lang

ASKER

Thanks for your reply. I have just managed to write some code that gives me the desired results.

The colour is returned within the dataset that is bound to the chart series. I have used...

series1.Points.DataBind(ds.Tables(0).Rows, "Name", "Value", "NameColour=NameColour")

Dim iRandom As New Random

For Each dp As DataPoint In series1.Points

	If Not String.IsNullOrEmpty(dp("NameColour").ToString) Then
		dp.Color = System.Drawing.ColorTranslator.FromHtml(dp("NameColour").ToString)
	Else
		dp.Color = Color.FromArgb(255, iRandom.Next(0, 255), iRandom.Next(0, 255), iRandom.Next(0, 255))
	End If

Next

Open in new window

I have provided a working solution using the details you have provided!
Thank you
I've requested that this question be closed as follows:

Accepted answer: 500 points for Éric Moreau's comment #a40922810
Assisted answer: 0 points for spen_lang's comment #a40922832

for the following reason:

This is what I ended up using.