Get Lighter / Darker color
-
I created a charting control for work in ASP.NET, and so far, they are thrilled. It has a bar chart, and a pie chart. Now they want a line chart (like a vertical bar). I have it working, but now they want each bar to look 3D. Each item is passed into a collection on the control. An item consists of a color and amount. The chart is built by the percentage of each item in the total of all items. Now they want the line chart (vertical bar) to have a 3D feel. I was able to get the 3D look, but I'm having a problem determining the values for the lighter and darker parts of each item. I need to figure out a lighter (and a darker) color for the passed value. For example, the bar color would be red. For the shadowed part of the bar, I need a darker red. For the top of the bar, I need a lighter color. But since each item color is being passed, I need to determine these colors on the fly. Something like GetDarkerColor(PassedColor) would be great. I just don't know how to determine these values. Any help would be greatly appreciated.
-
I created a charting control for work in ASP.NET, and so far, they are thrilled. It has a bar chart, and a pie chart. Now they want a line chart (like a vertical bar). I have it working, but now they want each bar to look 3D. Each item is passed into a collection on the control. An item consists of a color and amount. The chart is built by the percentage of each item in the total of all items. Now they want the line chart (vertical bar) to have a 3D feel. I was able to get the 3D look, but I'm having a problem determining the values for the lighter and darker parts of each item. I need to figure out a lighter (and a darker) color for the passed value. For example, the bar color would be red. For the shadowed part of the bar, I need a darker red. For the top of the bar, I need a lighter color. But since each item color is being passed, I need to determine these colors on the fly. Something like GetDarkerColor(PassedColor) would be great. I just don't know how to determine these values. Any help would be greatly appreciated.
Hi, you could convert to HSB (hue, saturation, brightness) using Color.GetXXX() methods, adjust brightness a bit, (watch out for over/underflow) and convert back. You need to write that part yourself ! This article[^] is my preferred article for june and may help you. BTW in the Java world GetLighter() and GetDarker() (or something of that nature) do exist. :)
Luc Pattyn
try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }