javafx面积图AreaChart

面积图主要强调数量随时间而变化的程度,引起人们对变化趋势的注意

javafx面积图AreaChart
javafx的chart的基本设置大体相通,可参考ScatterChart进行设置。

代码

package utility;

import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.chart.AreaChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart.Data;
import javafx.scene.chart.XYChart.Series;
import javafx.stage.Stage;

public class AreaChartUtility extends Application {

    private AreaChart 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 AreaChart.Series<Number, Number> createSeriesXN() {
    	final AreaChart.Series<Number, Number> series = new AreaChart.Series<>();
    	for(double i=-4;i<=4;i+=0.1) {
    		series.getData().add(new Data(i,normalDistribution(i,0,1)));
    	}
		return series;
    }
    public Series<Number, Number> createSeriesSinx() {
    	Series<Number, Number> series = new Series<>();
    	for(double i=-Math.PI;i<=Math.PI;i+=0.1) {
    		series.getData().add(new Data(i, Math.sin(i) ));
    	}
		return series;
    }
    public Parent createContent() {
        xAxis = new NumberAxis();
        xAxis.setLabel("X Values");
        yAxis = new NumberAxis();
        yAxis.setLabel("Y Values");
      
        chart = new AreaChart(xAxis, yAxis);
        Series<Number, Number> xn = createSeriesXN();
        xn.setName("X-N(0,1)");
        chart.getData().add(xn);
        

        return chart;
    }


    @Override public void start(Stage primaryStage) throws Exception {
        primaryStage.setScene(new Scene(createContent()));
        primaryStage.setTitle("AreaChart");
        primaryStage.show();
    }
    public static void main(String[] args) {
    	System.out.println(2 >>> 3);
        launch(args);
    }
}

javafx面积图AreaChart

//        Series<Number, Number> xn = createSeriesXN();
//        xn.setName("X-N(0,1)");
//        chart.getData().add(xn);
        Series<Number, Number> sinx = createSeriesSinx();
        sinx.setName("Sin(x)");
        chart.getData().add(sinx);

javafx面积图AreaChart

        Series<Number, Number> xn = createSeriesXN();
        xn.setName("X-N(0,1)");
        chart.getData().add(xn);
        Series<Number, Number> sinx = createSeriesSinx();
        sinx.setName("Sin(x)");
        chart.getData().add(sinx);

javafx面积图AreaChart

上一篇:LMS算法实现自适应滤波器(C语言版)


下一篇:【力扣算法】50-Pow(x,n)