-
Notifications
You must be signed in to change notification settings - Fork 402
Open
Description
Describe the bug
I want to render a stacked bar series on the default axis group (left), and a secondary line on the next axis (right). The line seems to be stacked on top of the bars, and this messes up the axis range too.
To Reproduce
public class StackedBarWithLine {
public static void main(String[] args) {
// Create chart
CategoryChart chart = new CategoryChartBuilder()
.width(800)
.height(600)
.title("Stacked Bars + Line on Secondary Axis")
.xAxisTitle("Category")
.yAxisTitle("Primary (Bars)")
.build();
// --- Style ---
chart.getStyler().setLegendVisible(true);
chart.getStyler().setStacked(true); // affects bar series only
chart.getStyler().setDefaultSeriesRenderStyle(CategorySeries.CategorySeriesRenderStyle.Bar);
chart.getStyler().setYAxisGroupPosition(1, Styler.YAxisPosition.Right); // right-hand axis
// --- Bar series (stacked, Y-axis 0) ---
chart.addSeries("Series A",
Arrays.asList("A", "B", "C", "D"),
Arrays.asList(10, 20, 15, 25));
chart.addSeries("Series B",
Arrays.asList("A", "B", "C", "D"),
Arrays.asList(5, 15, 10, 20));
chart.addSeries("Series C",
Arrays.asList("A", "B", "C", "D"),
Arrays.asList(8, 12, 18, 10));
// --- Line series (secondary Y-axis) ---
CategorySeries lineSeries = chart.addSeries("Trend Line",
Arrays.asList("A", "B", "C", "D"),
Arrays.asList(100, 150, 130, 180));
lineSeries.setChartCategorySeriesRenderStyle(CategorySeries.CategorySeriesRenderStyle.Line);
lineSeries.setYAxisGroup(1); // assign to secondary axis
lineSeries.setMarker(SeriesMarkers.CIRCLE);
// --- Label the secondary axis ---
chart.setYAxisGroupTitle(1, "Secondary (Line)");
// Display
new SwingWrapper<>(chart).displayChart();
}
}
Screenshots
Expected behavior
The axis groups should have ranges for their respective data. The bars should line up with values on the left axis, and the line on the right axis. The max of each axis in this example should be different, and the line should not be stacked on top of the bars.
geoff-tw
Metadata
Metadata
Assignees
Labels
No labels