openjdk-jfx icon indicating copy to clipboard operation
openjdk-jfx copied to clipboard

LineChart is clipping the series stroke at min and max

Open daveyostcom opened this issue 5 years ago • 1 comments
trafficstars

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

daveyostcom avatar Nov 02 '20 22:11 daveyostcom

This GitHub issue tracker is not actively tracked or managed. Please file a bug at bugreport.java.com and include your test program.

kevinrushforth avatar Nov 02 '20 22:11 kevinrushforth