代码
public class TestLineChart extends Application {
private LineChart chart;
private NumberAxis xAxis;
private NumberAxis yAxis;
public static double normalDistribution(double x, double u,double seta) {
return 1.0/(Math.sqrt(2.0*Math.PI)*seta)*Math.exp(
-0.5*Math.pow((x-u)/seta, 2));
}
public XYChart.Series<Double,Double> createSeries(){
Series series = new LineChart.Series<>();
series.setName("X-Y(0,1)");
for(double i=-4;i<=4;i+=0.1) {
series.getData().add(new Data(i,normalDistribution(i,0,1)));
}
return series;
}
public Parent createContent() {
xAxis = new NumberAxis();
xAxis.setLabel("X-Axis");
yAxis = new NumberAxis();
yAxis.setLabel("Y-Axis");
chart = new LineChart(xAxis, yAxis);
chart.setId("linechart");
chart.getData().add(createSeries());
chart.setTitle("折线图");
final String liveScatterChartCss =
getClass().getResource("LineChartUtility.css").toExternalForm();
chart.getStylesheets().add(liveScatterChartCss);
chart.setCreateSymbols(false);
return chart;
}
public void start(Stage primaryStage) throws Exception {
primaryStage.setScene(new Scene(createContent()));
primaryStage.show();
}
public static void main(String[] args) { launch(args);}
}
CSS
线的颜色
.default-color0.chart-series-line {
-fx-stroke:#55ddff
}
圈的颜色,圈的填充色
.chart-line-symbol.default-color0{
-fx-background-color: blue,red;
}
是否隐藏圈节点
.default-color0.chart-line-symbol { -fx-background-color: transparent; }
当然圈作为一个节点,当然是可以设置提示框的,请见Tooltip。