forked from roycan/cs131_finals_2016
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraph.java
More file actions
58 lines (45 loc) · 1.86 KB
/
Copy pathGraph.java
File metadata and controls
58 lines (45 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.stage.Stage;
public class Graph extends Application {
private static Double[] x, y, t;
private static String xName, yName, title;
private static double n;
public void init (Double[] x, Double[] y, Double[] t, double n, String xName, String yName, String title) {
Graph.x = x; Graph.y = y; Graph.t = t; Graph.xName = xName; Graph.yName = yName;
Graph.title = title; Graph.n = n;
main(null);
}
@Override public void start(Stage stage) {
final NumberAxis xAxis = new NumberAxis();
final NumberAxis yAxis = new NumberAxis();
xAxis.setLabel(xName);
yAxis.setLabel(yName);
final LineChart<Number,Number> lineChart = new LineChart<Number,Number>(xAxis,yAxis);
lineChart.setTitle(title);
XYChart.Series<Number, Number> series = new XYChart.Series<Number, Number>();
XYChart.Series<Number, Number> series1 = new XYChart.Series<Number, Number>();
series.setName("Lions");
series1.setName("Gazelles");
for (int i=1; i<n+1; i++){
series.getData().add(new XYChart.Data<Number, Number>(t[i], x[i]));
series1.getData().add(new XYChart.Data<Number, Number>(t[i], y[i]));
}
Scene scene = new Scene(lineChart,800,600);
lineChart.getData().add(series);
lineChart.getData().add(series1);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
@Override
public void stop() {
Platform.exit();
}
}