XChart icon indicating copy to clipboard operation
XChart copied to clipboard

Label of Last Bar in CategoryChart Not Visible

Open daniel-fontaine opened this issue 2 years ago • 4 comments

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.

daniel-fontaine avatar Oct 20 '22 22:10 daniel-fontaine

Thanks, I'll check it out soon hopefully. If you want, please create a PR with the fix.

timmolter avatar Nov 05 '22 14:11 timmolter

+1, running into this one, too.

Interestingly it doesn't happen all the time, but it does happen if I set the series colors on the ChartStyler. How is that related to the proposed "eliminate the redraw" fix?

mindlessolipsist avatar Jan 20 '23 10:01 mindlessolipsist

@mindlessolipsist For me, this is appearing whether or not I set the series colors on the ChartStyler.

@timmolter Is there any update on this issue?

abbas-aamir avatar Apr 19 '23 11:04 abbas-aamir

+1, last bar color depper,label missing image

Anricx avatar Jul 26 '23 02:07 Anricx