I'm depending on the version 8.1.1.
package com.example.chartfx;
import de.gsi.chart.XYChart;
import de.gsi.chart.axes.spi.DefaultNumericAxis;
import de.gsi.chart.legend.spi.DefaultLegend;
import de.gsi.dataset.spi.DoubleDataSet;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class SimpleChartSample extends Application {
private static final int N_SAMPLES = 100;
@Override
public void start(final Stage primaryStage) {
final StackPane root = new StackPane();
final XYChart chart = new XYChart(new DefaultNumericAxis(), new DefaultNumericAxis());
root.getChildren().add(chart);
// The new legend is not visible
chart.setLegend(new DefaultLegend());
// Uncomment the following 2 lines to enable current workaround:
// chart.setLegendVisible(false);
// chart.setLegendVisible(true);
final DoubleDataSet dataSet1 = new DoubleDataSet("data set #1");
final DoubleDataSet dataSet2 = new DoubleDataSet("data set #2");
// lineChartPlot.getDatasets().add(dataSet1); // for single data set
chart.getDatasets().addAll(dataSet1, dataSet2); // two data sets
final double[] xValues = new double[N_SAMPLES];
final double[] yValues1 = new double[N_SAMPLES];
final double[] yValues2 = new double[N_SAMPLES];
for (int n = 0; n < N_SAMPLES; n++) {
xValues[n] = n;
yValues1[n] = Math.cos(Math.toRadians(10.0 * n));
yValues2[n] = Math.sin(Math.toRadians(10.0 * n));
}
dataSet1.set(xValues, yValues1);
dataSet2.set(xValues, yValues2);
final Scene scene = new Scene(root, 800, 600);
primaryStage.setTitle(this.getClass().getSimpleName());
primaryStage.setScene(scene);
primaryStage.setOnCloseRequest(evt -> System.exit(0));
primaryStage.show();
}
public static void main(final String[] args) {
Application.launch(args);
}
}