package
candlestickchart.sample;
import
candlestickchart.CandleStickChart;
import
candlestickchart.CandleStickExtraValues;
import
javafx.application.Application;
import
javafx.collections.FXCollections;
import
javafx.collections.ObservableList;
import
javafx.scene.Parent;
import
javafx.scene.Scene;
import
javafx.scene.chart.NumberAxis;
import
javafx.scene.chart.XYChart;
import
javafx.stage.Stage;
public
class
CandleStickChartSample
extends
Application {
private
static
final
double
[][] data =
new
double
[][]{
{
1
,
17.9
,
17.9
,
17.69
,
17.77
,
17.795
},
{
2
,
18.43
,
18.48
,
17.64
,
17.87
,
18.06
},
{
3
,
18.9
,
18.99
,
18.52
,
18.57
,
18.755
},
{
4
,
19.31
,
19.42
,
18.86
,
18.89
,
19.14
},
{
5
,
18.9
,
19.63
,
18.87
,
19.31
,
19.25
},
{
6
,
18.83
,
18.99
,
18.72
,
18.77
,
18.855
},
{
7
,
18.74
,
18.91
,
18.51
,
18.52
,
18.71
},
{
8
,
19
,
19.04
,
18.52
,
18.55
,
18.78
},
{
9
,
19.23
,
19.3
,
18.73
,
19.17
,
19.015
},
{
10
,
19.38
,
19.72
,
19.26
,
19.27
,
19.49
},
{
11
,
19.55
,
19.64
,
19.45
,
19.61
,
19.545
},
{
12
,
19.34
,
19.66
,
19.34
,
19.51
,
19.5
},
{
13
,
19.28
,
19.41
,
19.06
,
19.22
,
19.235
},
{
14
,
19.59
,
19.59
,
19.19
,
19.21
,
19.39
},
{
15
,
19.96
,
20.16
,
19.63
,
19.78
,
19.895
},
{
16
,
20.22
,
20.28
,
20.01
,
20.06
,
20.145
},
{
17
,
20.24
,
20.46
,
20.08
,
20.1
,
20.27
},
{
18
,
19.84
,
20.13
,
19.83
,
19.96
,
19.98
},
{
19
,
19.79
,
19.95
,
19.7
,
19.86
,
19.825
},
{
20
,
19.83
,
19.93
,
19.68
,
19.72
,
19.805
},
{
21
,
19.62
,
19.86
,
19.58
,
19.84
,
19.72
},
{
22
,
19.79
,
19.9
,
19.52
,
19.54
,
19.71
},
{
23
,
19.64
,
19.85
,
19.57
,
19.82
,
19.71
},
{
24
,
19.45
,
19.79
,
19.34
,
19.71
,
19.565
},
{
25
,
19.74
,
19.79
,
19.59
,
19.62
,
19.69
},
{
26
,
20.04
,
20.11
,
19.74
,
19.78
,
19.925
},
{
27
,
20
,
20.14
,
19.96
,
20.04
,
20.05
},
{
28
,
19.82
,
20.01
,
19.71
,
19.91
,
19.86
},
{
29
,
20.14
,
20.24
,
19.81
,
19.87
,
20.025
},
{
30
,
20.04
,
20.23
,
19.93
,
20.15
,
20.08
},
{
31
,
20.24
,
20.31
,
19.86
,
20.06
,
20.085
},
{
32
,
20.54
,
20.59
,
20.33
,
20.36
,
20.46
},
{
33
,
20.27
,
20.59
,
20.09
,
20.38
,
20.34
},
{
34
,
20.03
,
20.34
,
20.03
,
20.31
,
20.185
},
{
35
,
20.43
,
20.43
,
20.06
,
20.13
,
20.245
},
{
36
,
20.34
,
20.6
,
20.29
,
20.36
,
20.445
},
{
37
,
19.96
,
20.5
,
19.96
,
20.34
,
20.23
},
{
38
,
20.11
,
20.24
,
19.88
,
19.99
,
20.06
},
{
39
,
20.18
,
20.28
,
20.07
,
20.14
,
20.175
},
{
40
,
19.83
,
20.26
,
19.82
,
20.15
,
20.04
},
{
41
,
19.95
,
20.07
,
19.87
,
19.91
,
19.97
},
{
42
,
20.2
,
20.33
,
19.93
,
19.99
,
20.13
},
{
43
,
20.26
,
20.34
,
20.02
,
20.19
,
20.18
},
{
44
,
20.57
,
20.59
,
20.12
,
20.2
,
20.355
},
{
45
,
20.03
,
20.1
,
19.79
,
19.86
,
19.945
},
{
46
,
19.95
,
20.04
,
19.78
,
19.93
,
19.91
},
{
47
,
19.91
,
19.99
,
19.78
,
19.89
,
19.885
},
{
48
,
19.8
,
19.96
,
19.73
,
19.92
,
19.845
},
{
49
,
19.78
,
19.85
,
19.65
,
19.69
,
19.75
},
{
50
,
19.21
,
19.67
,
19.2
,
19.56
,
19.435
},
{
51
,
19.45
,
19.56
,
19.17
,
19.45
,
19.365
},
{
52
,
19.77
,
19.84
,
19.32
,
19.36
,
19.58
},
{
53
,
19.98
,
20.08
,
19.86
,
19.88
,
19.97
},
{
54
,
19.93
,
20.11
,
19.82
,
19.98
,
19.965
},
{
55
,
19.92
,
19.92
,
19.65
,
19.79
,
19.785
},
{
56
,
19.95
,
20.01
,
19.63
,
20.01
,
19.82
},
{
57
,
20.13
,
20.49
,
19.99
,
20.04
,
20.24
},
{
58
,
20.53
,
20.55
,
19.64
,
19.97
,
20.095
},
{
59
,
22.27
,
22.35
,
21.75
,
21.8
,
22.05
},
{
60
,
22.14
,
22.24
,
21.95
,
22.17
,
22.095
},
{
61
,
22.26
,
22.42
,
22.01
,
22.31
,
22.215
},
{
62
,
22.27
,
22.67
,
22.06
,
22.29
,
22.365
},
{
63
,
21.71
,
21.93
,
21.68
,
21.76
,
21.805
},
{
64
,
21.7
,
21.76
,
21.37
,
21.49
,
21.565
},
{
65
,
22.2
,
22.22
,
21.71
,
21.88
,
21.965
},
{
66
,
22.06
,
22.71
,
22.05
,
22.55
,
22.38
}
};
private
CandleStickChart chart;
private
NumberAxis xAxis;
private
NumberAxis yAxis;
public
Parent createContent() {
xAxis =
new
NumberAxis(
0
,
67
,
1
);
xAxis.setMinorTickCount(
0
);
yAxis =
new
NumberAxis(
17
,
23
,
1
);
chart =
new
CandleStickChart(xAxis, yAxis);
chart.setTitle(
"ローソク足チャートのサンプル"
);
xAxis.setLabel(
"日付(順序)"
);
yAxis.setLabel(
"株価 (USD)"
);
XYChart.Series<Number, Number> series =
new
XYChart.Series<>();
for
(
double
[] day : data) {
series.getData().add(
new
XYChart.Data<>(day[
0
], day[
5
],
new
CandleStickExtraValues(day[
1
], day[
2
], day[
3
], day[
4
])));
}
ObservableList<XYChart.Series<Number, Number>> stockData = chart.getData();
if
(stockData ==
null
) {
stockData = FXCollections.observableArrayList(series);
chart.setData(stockData);
}
else
{
chart.getData().add(series);
}
return
chart;
}
@Override
public
void
start(Stage primaryStage)
throws
Exception {
Scene scene =
new
Scene(createContent(),
600
,
400
);
primaryStage.setScene(scene);
primaryStage.show();
}
/**
* Java main for when running without JavaFX launcher
*
* @param args command line arguments
*/
public
static
void
main(String[] args) {
launch(args);
}
}