【问题标题】:Remove padding between plot and the axis - xchart删除绘图和轴之间的填充 - xchart
【发布时间】:2022-10-07 15:53:07
【问题描述】:

目前,我已经创建了这个图表。但我似乎无法在文档中找到任何删除绘图和 x / y 轴之间填充的函数(见下图)。

只是这样可以复制,我在下面包含了我的代码。

 // Create Chart

        XYChart chart = new XYChartBuilder().width(640).height(450).build();

        // Customize Char


        chart.getStyler().setPlotBorderVisible(false);
        chart.getStyler().setMarkerSize(0);
        chart.getStyler().setPlotGridLinesVisible(false);
        chart.getStyler().setAxisTicksVisible(false);
        chart.getStyler().setLegendVisible(false);
        chart.getStyler().setChartPadding(0);

        chart.getStyler().setDefaultSeriesRenderStyle(XYSeries.XYSeriesRenderStyle.Area);

        // Series
        chart.addSeries(\"a\", new double[] { 0, 3, 5}, new double[] { -3, 5, 9});
        chart.addSeries(\"b\", new double[] { 5, 7, 9 }, new double[] { 9, 6, 5});


        try {
            BitmapEncoder.saveBitmap(chart, \"./report-template/chart/Sample_Chart.png\", BitmapEncoder.BitmapFormat.PNG);

        } catch (IOException e) {
            throw new RuntimeException( \"Failed to save the chart!!! \\n\" + e);
        }

    标签: java graph


    【解决方案1】:

    我尝试同样的事情,它对我有帮助。

    chart.getStyler().setPlotContentSize(1d);
    

    文件:https://knowm.org/javadocs/xchart/org/knowm/xchart/style/Styler.html#setPlotContentSize(double)

    【讨论】: