Skip to content

Label of Last Bar in CategoryChart Not Visible  #707

@daniel-fontaine

Description

@daniel-fontaine

When creating a CategoryChart with bar styling and visible labels, the label of the last bar in the series is not visible. This is a new bug introduced in the latest release of the library. The following code will demonstrate the issue:

        double[] xData = new double[] { 0.0, 1.0, 2.0, 3.0, 4.0 };                                                                                                                            
        double[] yData = new double[] { 2.0, 1.5, 4.0, 3.77, 2.5 };                                                                                                                           
                                                                                                                                                                                              
        // Create Chart                                                                                                                                                                       
        CategoryChartBuilder builder = new CategoryChartBuilder();                                                                                                                            
        builder.title("Sample Chart")                                                                                                                                                         
            .xAxisTitle("X")                                                                                                                                                                  
            .yAxisTitle("Y")                                                                                                                                                                  
            .theme(Styler.ChartTheme.Matlab);                                                                                                                                                 
        CategoryChart chart = builder.build();                                                                                                                                                
        // chart.getStyler().setYAxisMin(1.0);                                                                                                                                                
        chart.getStyler().setLabelsVisible(true);                                                                                                                                             
        //.setDefaultSeriesRenderStyle(CategorySeries.CategorySeriesRenderStyle.Line).                                                                                                        
                                                                                                                                                                                              
        chart.addSeries("y(x)", xData, yData);                                                                                                                                                
                                                                                                                                                                                              
        // Show it                                                                                                                                                                            
        new SwingWrapper(chart).displayChart();

I have looked into the issue myself and the error occurs because the final bar in the series is drawn twice, with the second rendering overwriting the label. This extra rendering occurs due to a call to closePath on line 510 of PlotContent_Category_Bar.java that should not occur. I can fix this issue for the above example by setting 'path = null;' on line 312 following the first rendering of the bar. I am not sure if this bug occurs in other permutations of the CategoryChart. If so, my fix likely does not address those bugs. I hope this helps. Thanks for the hard work on this library.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions