I have a bar chart whose columns I’d like to apply a linear gradient fill to via the setStyle method. In the method I’m using to configure the colors, the following code sets the gradient:
public function configureColor(series:Series):void {
var lg:LinearGradient = GradientUtil.getLinearGradient([color1, color2], 0.8, 45);
series.setStyle("fill", lg);
...
}
The getLinearGradient method:
public function getLinearGradient(colors:Array, alpha:Number, angle:Number = 0.0):LinearGradient {
var lg:LinearGradient = new LinearGradient();
lg.angle = angle;
var entries:Array = []
for each (var color:uint in colors) {
entries.push(new GradientEntry(color, NaN, alpha));
}
lg.entries = entries;
return lg;
}
For some reason, the gradients that I get on the columns are “choppy”. The transition from one color to the next occurs in a very small section of the column, rather than a smooth transition from the top to the bottom of the bar. How can I get it so that it does end up being a smooth transition?
Edit: Example of what the issue I’m having looks like

This seems to be a problem with the
LinearGradientclass. My initial assumption was that it was theBoxItemRendererthat draws the fill in the chart. But looking there pointed me at the gradient’sbegin()method which the renderer uses to begin the fill.The problem is perhaps a special case, that is noticeable when using non-90 degree angles on a rectangle who’s width to height ratio is large. You can recreate this problem with a simple rect:
My hacky solution was to extend
LinearGradientand override itsbegin()method. I copied the original code, and commented out a few lines that made it determine the wrong width. I tested that w/various angles and it seems to render OK.Admittedly, I don’t understand the purpose of the lines I commented out, and there is probably a valid use case.
[Edit] Commented out the entire if statement and use the max dimension for the
lengthinstead. Original hack only commented out theif (normalizedAngle > hypotenuseAngle)clause. Probably still buggy, but addresses both problem cases.