forked from fair-acc/chart-fx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LogAxisSample.java
78 lines (68 loc) · 2.77 KB
/
LogAxisSample.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
package de.gsi.chart.samples;
import de.gsi.chart.XYChart;
import de.gsi.chart.axes.spi.DefaultNumericAxis;
import de.gsi.chart.plugins.EditAxis;
import de.gsi.chart.plugins.Zoomer;
import de.gsi.dataset.spi.DoubleDataSet;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
/**
*
* Simple example of chart with log axis
*
* @author rstein
*
*/
public class LogAxisSample extends Application {
private static final int N_SAMPLES = 1000;
@Override
public void start(final Stage primaryStage) {
final StackPane root = new StackPane();
DefaultNumericAxis xAxis = new DefaultNumericAxis();
DefaultNumericAxis yAxis = new DefaultNumericAxis();
yAxis.setLogAxis(true);
// yAxis.setLogarithmBase(2);
final XYChart chart = new XYChart(xAxis, yAxis);
final Zoomer zoomer = new Zoomer();
zoomer.setPannerEnabled(false); // not recommended (ie. Axes do not support complex numbers, e.g. 'log(-1)')
chart.getPlugins().add(zoomer); // zoom around
chart.getPlugins().add(new EditAxis()); // manually modify axis
root.getChildren().add(chart);
final DoubleDataSet dataSet1 = new DoubleDataSet("data set #1");
final DoubleDataSet dataSet2 = new DoubleDataSet("data set #2");
final DoubleDataSet dataSet3 = new DoubleDataSet("data set #2");
chart.getDatasets().addAll(dataSet1, dataSet2, dataSet3);
// classic way of adding data points
// N.B. in a life-update context every new points triggers a chart
// repaint. This can be suppressed by adding/setting full arrays and/or
// by selecting dataSet1.setAutoNotification(false/true) for the data
// sets (or chart) concerned to suppress this repaint.
dataSet1.autoNotification().set(false);
dataSet2.autoNotification().set(false);
dataSet3.autoNotification().set(false);
for (int n = 0; n < N_SAMPLES; n++) {
final double x = n + 1.0;
double y = 0.01 * (n + 1);
dataSet1.add(x, 2.0 * x);
dataSet2.add(x, Math.pow(2, y));
dataSet3.add(x, Math.exp(y));
}
dataSet1.autoNotification().set(true);
dataSet2.autoNotification().set(true);
dataSet3.autoNotification().set(true);
final Scene scene = new Scene(root, 800, 600);
primaryStage.setTitle(this.getClass().getSimpleName());
primaryStage.setScene(scene);
primaryStage.setOnCloseRequest(evt -> Platform.exit());
primaryStage.show();
}
/**
* @param args the command line arguments
*/
public static void main(final String[] args) {
Application.launch(args);
}
}