我怎样才能告诉 StackedBarChart 的轴表现?

How can I tell the axes of a StackedBarChart to behave?

情况如下:

图表初始化如下:

protected NumberAxis xAxis;
protected NumberAxis yAxis;
protected StackedAreaChart<Number, Number> chart;

protected final XYChart.Series<Number, Number> waitingSeries
    = new XYChart.Series<>();
protected final XYChart.Series<Number, Number> startedSeries
    = new XYChart.Series<>();
protected final XYChart.Series<Number, Number> successSeries
    = new XYChart.Series<>();
protected final XYChart.Series<Number, Number> failureSeries
    = new XYChart.Series<>();

// ...

@Override
public void init()
{
    // ...

    xAxis = new NumberAxis();
    xAxis.setLabel("Line number");
    xAxis.setForceZeroInRange(false);
    xAxis.setTickUnit(1.0);
    xAxis.setTickMarkVisible(false);

    yAxis = new NumberAxis();
    yAxis.setTickMarkVisible(false);

    chart = new StackedAreaChart<>(xAxis, yAxis);

    chart.setAnimated(false);
    chart.setTitle("Matcher status by line");

    waitingSeries.setName("Waiting for children");
    startedSeries.setName("Started this line");
    successSeries.setName("Succeeded this line");
    failureSeries.setName("Failed this line");

    final ObservableList<XYChart.Series<Number, Number>> data
        = chart.getData();

    data.add(waitingSeries);
    data.add(startedSeries);
    data.add(successSeries);
    data.add(failureSeries);

    pane.setCenter(chart);
}

好的,所以:

(解决 SO 聊天和项目符号列表与代码的错误)

@Override
public void showLineMatcherStatus(final List<LineMatcherStatus> list,
    final int startLine, final int nrLines)
{
    display.xAxis.setLowerBound(startLine);
    display.xAxis.setUpperBound(startLine + nrLines - 1);
    // etc

startLine 在这种情况下是 1,nrLines 是 25,好吧,endLine 是 25。很好,边界得到尊重...

...但是为什么x轴的范围是0到27.5??

如何使坐标轴行为?

默认情况下,NumberAxis 已将 autoRanging 设置为 true,因此要使其符合您的下限和上限,您需要

xAxis.setAutoRanging(false);

对于刻度线,如果您仔细观察图像,您会发现实际数字旁边没有刻度线;仅在"minor values"之间。

所以你需要两者

xAxis.setTickMarkVisible(false);

xAxis.setMinorTickVisible(false);