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

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

Open
daveyostcom opened this issue Nov 2, 2020 · 1 comment
Open

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

daveyostcom opened this issue Nov 2, 2020 · 1 comment

Comments

@daveyostcom
Copy link

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

@kevinrushforth
Copy link
Collaborator

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants