Skip to content

Mixed series render style legend layout #892

@JamesPaceOnTailwind

Description

@JamesPaceOnTailwind

Describe the bug
When you have series using different render styles, like bar and line, the legend markers and text is displayed wonky.

To Reproduce

package com.ontailwind.main.reporting.loss.list;

import java.awt.*;
import java.util.Arrays;
import org.knowm.xchart.CategoryChartBuilder;
import org.knowm.xchart.CategorySeries;
import org.knowm.xchart.SwingWrapper;
import org.knowm.xchart.style.Styler;
import org.knowm.xchart.style.markers.SeriesMarkers;

public class MixedChartExample {

  public static void main(String[] args) {
    // Create chart
    var chart =
        new CategoryChartBuilder()
            .width(800)
            .height(600)
            .title("Bar + Line Series Legend Marker Demo")
            .xAxisTitle("Category")
            .yAxisTitle("Value")
            .build();

    // General Styler settings
    chart.getStyler().setLegendPosition(Styler.LegendPosition.OutsideS);
    chart.getStyler().setLegendLayout(Styler.LegendLayout.Horizontal);
    chart.getStyler().setLegendVisible(true);

    // Bar Series
    var barSeries =
        chart.addSeries("Bar Series", Arrays.asList("A", "B", "C"), Arrays.asList(20, 40, 55));
    barSeries.setChartCategorySeriesRenderStyle(CategorySeries.CategorySeriesRenderStyle.Bar);
    barSeries.setFillColor(new Color(35, 127, 211));

    // Line Series
    var lineSeries =
        chart.addSeries("Line Series", Arrays.asList("A", "B", "C"), Arrays.asList(15, 30, 45));
    lineSeries.setChartCategorySeriesRenderStyle(CategorySeries.CategorySeriesRenderStyle.Line);
    lineSeries.setLineColor(new Color(237, 133, 53));
    lineSeries.setLineWidth(2.5f);
    lineSeries.setMarker(SeriesMarkers.CIRCLE);

    // Show chart
    new SwingWrapper<>(chart).displayChart();
  }
}

Screenshots

Image

Expected behavior
The horizontal legend should display the legend markers and text uniformly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions