fge
fge

Reputation: 121830

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

Here is the situation:

enter image description here

The graph is initialized as such:

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

OK, so:

(work around bug with SO chat and bullet list vs code)

@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 in this case is 1 and nrLines being 25, well, endLine is 25. Good, the bounds are respected...

... But then why does the x axis range from 0 to 27.5??

How do I make the axes behave?

Upvotes: 0

Views: 45

Answers (1)

James_D
James_D

Reputation: 209694

By default, NumberAxis has autoRanging set to true, so to get it to respect your lower and upper bounds you need

xAxis.setAutoRanging(false);

For the tick marks, if you look at your image closely, you'll notice there are no tick marks next to the actual numbers; only at the "minor values" in between.

So you need both

xAxis.setTickMarkVisible(false);

and

xAxis.setMinorTickVisible(false);

Upvotes: 1

Related Questions