You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Re-labeling this as a Feature Request — gradient fill for category bar charts isn't supported today (bars are painted with a single flat series.getFillColor()), so I'm tracking it as an enhancement rather than a how-to.
How it could be implemented in the future
The bar fill happens in one place, PlotContent_Category (and its sibling PlotContent_HorizontalBar):
Since Graphics2D.fill() accepts any java.awt.Paint, a vertical gradient is a small, localized change — swap the flat color for a GradientPaint:
Colorfill = series.getFillColor();
g.setPaint(newGradientPaint(
(float) xOffset, (float) zeroOffset, fill, // bar base
(float) xOffset, (float) yOffset, fill.brighter() // bar top
));
g.fill(barPath);
To do it properly as an opt-in, backward-compatible feature, the work would be roughly:
Add a setting to CategoryStyler (e.g. setBarFillGradientEnabled(boolean), optionally with a configurable end color).
Gate the GradientPaint branch behind that flag in PlotContent_Category, keeping the current flat fill as the default.
Mirror the same logic in PlotContent_HorizontalBar for orientation parity, and update the legend marker fill so the legend matches the bars.
Add a demo to the bar-chart examples in xchart-demo.
Note that XChart already has gradient interpolation infrastructure for heat maps (Styler.getRangeColors() + the gradient color logic in PlotContent_HeatMap), which could serve as a reference if multi-stop gradients are ever wanted here.
In the meantime, the GradientPaint snippet above can be applied in a custom build/fork to achieve the effect today.
CategoryStyler and HorizontalBarStyler add setBarFillGradientEnabled, initialized false so existing charts keep the flat fill. When the flag is on, PlotContent_Category and PlotContent_HorizontalBar fill each bar with a non-cyclic GradientPaint from the series fill at the segment base to fill.brighter() at the value end; negative bars reverse those ends, coincident endpoints stay flat, and the Graphics2D paint from before the gradient is restored.
Activity
timmolter commentedon Jun 22, 2026
Re-labeling this as a Feature Request — gradient fill for category bar charts isn't supported today (bars are painted with a single flat
series.getFillColor()), so I'm tracking it as an enhancement rather than a how-to.How it could be implemented in the future
The bar fill happens in one place,
PlotContent_Category(and its siblingPlotContent_HorizontalBar):Since
Graphics2D.fill()accepts anyjava.awt.Paint, a vertical gradient is a small, localized change — swap the flat color for aGradientPaint:To do it properly as an opt-in, backward-compatible feature, the work would be roughly:
CategoryStyler(e.g.setBarFillGradientEnabled(boolean), optionally with a configurable end color).GradientPaintbranch behind that flag inPlotContent_Category, keeping the current flat fill as the default.PlotContent_HorizontalBarfor orientation parity, and update the legend marker fill so the legend matches the bars.xchart-demo.Note that XChart already has gradient interpolation infrastructure for heat maps (
Styler.getRangeColors()+ the gradient color logic inPlotContent_HeatMap), which could serve as a reference if multi-stop gradients are ever wanted here.In the meantime, the
GradientPaintsnippet above can be applied in a custom build/fork to achieve the effect today.PRs welcome!
mvanhorn commentedon Oct 13, 2026
CategoryStyler and HorizontalBarStyler add setBarFillGradientEnabled, initialized false so existing charts keep the flat fill. When the flag is on, PlotContent_Category and PlotContent_HorizontalBar fill each bar with a non-cyclic GradientPaint from the series fill at the segment base to fill.brighter() at the value end; negative bars reverse those ends, coincident endpoints stay flat, and the Graphics2D paint from before the gradient is restored.
#1037