如何判断StackedBarChart的轴是否表现?

时间:2015-02-07 21:26:57

标签: java graphics charts javafx javafx-8

情况如下:

enter image description here

图表初始化如下:

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);
}

好的,所以:

  • 即使我在两个轴上设置了刻度标记不可见,它们也是;
  • 即使我告诉xAxis它的步骤应为1,它也会显示分数;
  • 然后有这个,我更新数据:

(解决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 ??

如何使轴表现?

1 个答案:

答案 0 :(得分:1)

默认情况下,NumberAxisautoRanging设置为true,因此要让它尊重您需要的下限和上限

xAxis.setAutoRanging(false);

对于刻度线,如果仔细观察图像,您会注意到实际数字旁边没有刻度线;只是在两者之间的“次要价值”。

所以你需要两个

xAxis.setTickMarkVisible(false);

xAxis.setMinorTickVisible(false);