For Each dp As DataPoint In chrtDemo.Series(0).Points
R = randomNo.Next(256)
G = randomNo.Next(256)
B = randomNo.Next(256)
dp.Color = Drawing.Color.FromArgb(R, G, B) ' Random color for column
chrtDemo.Legends(0).CustomItems.Add(dp.Color, dp.AxisLabel) ' Display label & column color in Legend
Next
Marked as answer by StrangerMike on Apr 09, 2012 04:00 PM
Allowing my graph to go into 3D causes some problems as to the series order (one series blocks out the others).
I have to change the series order if 3D is requested.
Because of this I also have to change the color order of the series to match the inverted series order, the legend color did not cooperate as I would have hoped.
Paindaasp, I did not understand you code. Is there away to assign specific colors?
StrangerMike
Contributor
2707 Points
1732 Posts
How to change the mschart legend color
Apr 06, 2012 02:40 PM|LINK
Can anyone tell me how to change the color of the little rectangular color box in a mschart legend?
Thanks
sarathi125
Star
13599 Points
2691 Posts
Re: How to change the mschart legend color
Apr 06, 2012 03:43 PM|LINK
Hi,
Try this,
http://msdn.microsoft.com/en-us/library/bb677428.aspx
Remember to click Mark as Answer on the post that helps to others.
My Blog :MyAspSnippets
paindaasp
Star
12080 Points
2034 Posts
Re: How to change the mschart legend color
Apr 06, 2012 04:16 PM|LINK
This code will change the colors randomly:
For Each dp As DataPoint In chrtDemo.Series(0).Points R = randomNo.Next(256) G = randomNo.Next(256) B = randomNo.Next(256) dp.Color = Drawing.Color.FromArgb(R, G, B) ' Random color for column chrtDemo.Legends(0).CustomItems.Add(dp.Color, dp.AxisLabel) ' Display label & column color in Legend NextStrangerMike
Contributor
2707 Points
1732 Posts
Re: How to change the mschart legend color
Apr 09, 2012 03:59 PM|LINK
Thanks to both for reply.
Allowing my graph to go into 3D causes some problems as to the series order (one series blocks out the others).
I have to change the series order if 3D is requested.
Because of this I also have to change the color order of the series to match the inverted series order, the legend color did not cooperate as I would have hoped.
Paindaasp, I did not understand you code. Is there away to assign specific colors?
StrangerMike
Contributor
2707 Points
1732 Posts
Re: How to change the mschart legend color
Apr 09, 2012 04:00 PM|LINK
Perhaps this is the answer, which has no answer. It does not appear the legend item color can work independtly of the series color.
Unless paindaasp, some how does the trick.
paindaasp
Star
12080 Points
2034 Posts
Re: How to change the mschart legend color
Apr 09, 2012 05:40 PM|LINK
Yes, this will set the colors for the first 3 datapoints...
Dim dp As New DataPoint dp = chrtDemo.Series(0).Points(0) dp.Color = Drawing.Color.Navy chrtDemo.Legends(0).CustomItems.Add(dp.Color, dp.AxisLabel) dp = chrtDemo.Series(0).Points(1) dp.Color = Drawing.Color.Red chrtDemo.Legends(0).CustomItems.Add(dp.Color, dp.AxisLabel) dp = chrtDemo.Series(0).Points(2) dp.Color = Drawing.Color.Green chrtDemo.Legends(0).CustomItems.Add(dp.Color, dp.AxisLabel)