Skip to content
This repository was archived by the owner on Jun 24, 2021. It is now read-only.
This repository was archived by the owner on Jun 24, 2021. It is now read-only.

LineChart is clipping the series stroke at min and max #640

@daveyostcom

Description

@daveyostcom

When the value is at min or max, the stroke appears to be clipped.

I can't think of anything to try other than tweaking the background and the padding (see source).

LineChart series stroke clipped at min and max

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.stage.Stage;

public class LineChartClipping extends Application {

  LineChart.Series<Number, Number> series;

  LineChart<Number, Number> makeChart() {
    NumberAxis xAxis = new NumberAxis();
    NumberAxis yAxis = new NumberAxis(0, 1, .1);
    var chart = new LineChart<>(xAxis, yAxis) {
      @Override // Remove output clutter. Has no effect on the issue.
      protected void dataItemAdded(Series<Number, Number> series, int i, Data<Number, Number> item) {}
    };
    xAxis.setLowerBound(0);
    chart.setHorizontalGridLinesVisible(true);
    // Remove output clutter. Has no effect on the issue.
    chart.setLegendVisible(false);
    xAxis.setTickLabelsVisible       (false);
    xAxis.setTickMarkVisible         (false);
    xAxis.setMinorTickVisible        (false);
    chart.setVerticalGridLinesVisible(false);
    yAxis.setTickLabelsVisible       (false);
    yAxis.setTickMarkVisible         (false);
    series = new LineChart.Series<>();
    chart.getData().add(series);
    series.getNode().setStyle(String.format("-fx-stroke-width: %g;", 3.0));
    addSegments(0.5, 0.0, 1.0, 0.5, 0.1, 0.9, 0.5);
    // Ineffectual tweaks
 // chart.setBackground(new Background(new BackgroundFill(Color.color(0, 1, 1, .5), null, null)));
 // chart.setPadding(new Insets(5, 0, 5, 0)); // also tried negative
    return chart;
  }

  double x = 0;

  void addSegments(double... values) {
    for (var value : values) {
      addData(value);  x += 2;
      addData(value);
    }
  }

  private void addData(double value) {
    series.getData().add(new LineChart.Data<>(x, value));
  }


  @Override
  public void start(Stage stage) {
    var chart = makeChart();
    final Scene scene = new Scene(chart, 100, 100);
    stage.setScene(scene);
    stage.show();
  }

  public static void main(String[] args) {   launch(args);  }
}

macOS Catalina, Retina iMac (HiDPI)
JavaFX 15.0.1, Java 15.0.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions