-
Notifications
You must be signed in to change notification settings - Fork 0
/
ScatterChartSample1.java
128 lines (87 loc) · 3.76 KB
/
ScatterChartSample1.java
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javafxapplication1;
import Database.DatabaseConnection;
import java.sql.ResultSet;
import java.sql.SQLException;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
/**
*
* @author Ningesh
*/
import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.scene.Scene;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.ScatterChart;
import javafx.scene.chart.XYChart;
import javafx.stage.Stage;
public class ScatterChartSample1 extends Application {
Database.DatabaseConnection dbcon=new DatabaseConnection();
@Override public void start(Stage stage) throws SQLException {
stage.setTitle("Scatter Chart Sample");
final NumberAxis xAxis = new NumberAxis(41.5, 42.3, 0.01);
final NumberAxis yAxis = new NumberAxis(-87.5, -88.0, 0.01);
final ScatterChart<Number,Number> sc = new
ScatterChart<Number,Number>(xAxis,yAxis);
xAxis.setLabel("Age (years)");
yAxis.setLabel("Returns to date");
sc.setTitle("Investment Overview");
String qry="select * from mainclusters";
ResultSet rs=dbcon.getResultSet(qry);
int val=1;
XYChart.Series series1 = null;
XYChart.Series series2 = null ;
XYChart.Series series3 = null ;
series1 = new XYChart.Series();
series2 = new XYChart.Series();
series3 = new XYChart.Series();
series1.setName("Cluster 1");
series2.setName("Cluster 2");
series3.setName("Cluster 3");
// series1.getData().add(new XYChart.Data(2.8, 33.6));
// series1.getData().add(new XYChart.Data(2.0, 1.0));
// series1.getData().add(new XYChart.Data(2.0, 2.0));
// series1.getData().add(new XYChart.Data(2.0, 3.0));
while(rs.next()){
String clusterdata1[]=rs.getString("points").split(",");
// double datapoint=Double.parseDouble(rs.getString("centroid"));
for(int j=0;j<clusterdata1.length;j++)
{
String clusterdata[]=clusterdata1[j].split(" ");
// for(int k=0;k<clusterdata.length;k++){
double dataobt=Double.parseDouble(clusterdata[0]);
double dataobt1=Double.parseDouble(clusterdata[1]);
if(val==1){
series1.getData().add(new XYChart.Data(dataobt, dataobt1));
}
if(val==2){
// series2.getData().add(new XYChart.Data(2.8, 33.6));
series2.getData().add(new XYChart.Data(dataobt, dataobt1));
}
if(val==3){
// series3.getData().add(new XYChart.Data(2.8, 33.6));
series3.getData().add(new XYChart.Data(dataobt, dataobt1));
}
}
val++;
// }
}
sc.getData().addAll(series1, series2,series3);
Scene scene = new Scene(sc, 500, 400);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}