【问题标题】:How can I tell the axes of a StackedBarChart to behave?如何告诉 StackedBarChart 的轴的行为?
【发布时间】:2015-02-07 21:26:57
【问题描述】:

情况如下:

图形被初始化为:

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??

如何使坐标区正常运行?

【问题讨论】:

  • 只是快速猜测,没有时间测试,但您可能需要xAxis.setAutoRanging(false);
  • @James_D 确实,解决了 x 轴问题!

标签: java graphics charts javafx javafx-8


【解决方案1】:

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

xAxis.setAutoRanging(false);

对于刻度线,如果您仔细查看图像,您会发现实际数字旁边没有刻度线;仅在两者之间的“次要价值”。

所以你需要两个

xAxis.setTickMarkVisible(false);

xAxis.setMinorTickVisible(false);

【讨论】:

  • 是的,后来我找到了,但感谢自动测距提示!
猜你喜欢
  • 1970-01-01
  • 2014-05-29
  • 1970-01-01
  • 1970-01-01
  • 2013-12-28
  • 2010-12-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多