Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Histogram or Barchart not drawing last Bar #489

Open
Tracked by #527
ahmadnav opened this issue Feb 25, 2022 · 0 comments
Open
Tracked by #527

Histogram or Barchart not drawing last Bar #489

ahmadnav opened this issue Feb 25, 2022 · 0 comments
Labels
Milestone

Comments

@ahmadnav
Copy link

Describe the bug
When drawing a bar chart using histogram renderer (Very similar to the ones in example) the last bar graph isn't drawn. When the following code is ran the last bar (9 category) is not drawn as shown in lastBarNotDrawn.png. How ever if I add one extra data point at uknown category (which would be 10) the 9 category bar is drawn as shown in lastBarDrawnWithUC.png.
To Reproduce
The following code is ran and the XYChart displayed in a Stage stack pane. But the XYchart can be displayed any where. Also you can just use the generateMultiSeriesBarChart function to create a chart and add DataSeries to it.

Thank you for this very helpful library and looking into this issue.

        final DefaultDataSet dataSet = new DefaultDataSet("Data 1");
        dataSet.setStyle("strokeColor=black;fillColor=black;strokeWidth=1.0");
        final DefaultDataSet dataSet1 = new DefaultDataSet("Data 2");
        int sampleSize = 10;
        ArrayList<String> categories = new ArrayList<String>();
        for (int n = 0; n < sampleSize; n++) {
            categories.add(String.valueOf(n));
        }

        ArrayList<DefaultDataSet> dataSets = new ArrayList<>();
        dataSets.add(dataSet);
        dataSets.add(dataSet1);

        XYChart c = chartFX.generateMultiSeriesBarChart("xAxis Name","yAxis Name",categories,dataSets); 
        root.getChildren().add(c); 
        ((CategoryAxis)c.getAxes().get(0)).setMaxMajorTickLabelCount(sampleSize);

        Platform.runLater(()->{
            for (int n =0 ; n < sampleSize; n++) {
                ((DefaultDataSet)c.getRenderers().get(0).getDatasets().get(0)).add(n,n+1);
                ((DefaultDataSet)c.getRenderers().get(0).getDatasets().get(1)).add(n,n*2);
            }
        });

    public XYChart generateMultiSeriesBarChart(String xAxisName, String yAxisName, ArrayList<String> categories,ArrayList<DefaultDataSet> dataSets){

        final CategoryAxis categoryAxis = new CategoryAxis(xAxisName); 
        categoryAxis.setCategories(categories);
        categoryAxis.setOverlapPolicy(AxisLabelOverlapPolicy.SHIFT_ALT);

        final DefaultNumericAxis yAxis = new DefaultNumericAxis(yAxisName); 


        // Renderer Setup
        final HistogramRenderer renderer = new HistogramRenderer();
        renderer.setPolyLineStyle(LineStyle.NONE);
        renderer.setDrawBars(true);
        renderer.setShiftBar(true);
        renderer.setDrawMarker(false);
        renderer.setBarWidthPercentage(50.0);
        // Set axes and dataset.
        renderer.getDatasets().setAll(dataSets);

        final XYChart lineChartPlot = new XYChart(categoryAxis,yAxis);
        lineChartPlot.setAnimated(false);
        lineChartPlot.legendVisibleProperty().set(true);
        lineChartPlot.getRenderers().setAll(renderer);

        // Plugins
        lineChartPlot.getPlugins().add(new ParameterMeasurements());
        lineChartPlot.getPlugins().add(new EditAxis());
        final Zoomer zoomer = new Zoomer();
        lineChartPlot.getPlugins().add(zoomer);

        return lineChartPlot;
    }

Environment:

  • OS: Ubuntu 20.04.1 LTS

  • Java version: 11.0.13

  • JavaFx version: 11.0.2

  • ChartFx version: [11.2.5]
    lastBarNotDrawn
    lastBarDrawnWithUC

@ahmadnav ahmadnav added the bug label Feb 25, 2022
@ahmadnav ahmadnav changed the title Histogram or Barchart not drawing last value Histogram or Barchart not drawing last Bar Feb 25, 2022
@wirew0rm wirew0rm mentioned this issue Jun 28, 2022
27 tasks
@wirew0rm wirew0rm added this to the chartfx 11.3 milestone Jun 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants