ale*_*lex 2 css java plot javafx scatter-plot
我ScatterChart在 JavaFX 中做了这个:
如何设置数据点大小?
我发现它应该在 CSS 中完成,但即使有docs,我仍然无法弄清楚。
用
.chart-symbol {
-fx-background-radius: 10px ;
-fx-padding: 10px ;
}
Run Code Online (Sandbox Code Playgroud)
如果您需要将其仅应用于特定图表,请为图表指定一个 id 并在 CSS 文件中使用该 id:
chart.setId("bifurcation-diagram");
Run Code Online (Sandbox Code Playgroud)
chart.setId("bifurcation-diagram");
Run Code Online (Sandbox Code Playgroud)
SSCCE:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.ScatterChart;
import javafx.scene.chart.XYChart.Data;
import javafx.scene.chart.XYChart.Series;
import javafx.stage.Stage;
public class ScatterChartExample extends Application {
@Override
public void start(Stage primaryStage) {
ScatterChart<Number, Number> chart = new ScatterChart<>(new NumberAxis(), new NumberAxis());
chart.setId("bifurcation-diagram");
Series<Number, Number> series = new Series<>();
chart.getData().add(series);
for (int i = 0 ; i <= 100; i++) {
double lambda = 4.0 * i / 100 ;
double x = 0.5 ;
for (int j = 0 ; j < 100 ; j++) {
x = lambda * x * (1-x);
}
for (int j = 0 ; j < 50; j++) {
series.getData().add(new Data<>(lambda, x));
x = lambda * x * (1-x);
}
}
Scene scene = new Scene(chart, 1200, 800);
scene.getStylesheets().add("bifurcation.css");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Run Code Online (Sandbox Code Playgroud)
分叉.css:
#bifurcation-diagram .chart-symbol {
-fx-background-radius: 10px ;
-fx-padding: 10px ;
}
Run Code Online (Sandbox Code Playgroud)
如果你想要更小的点,这似乎效果不佳(我假设是因为它们与为图表数据生成的默认节点不兼容)。在这种情况下,您可能还需要为数据设置节点:
for (int i = 0 ; i <= 400; i++) {
double lambda = 1.0 * i / 100 ;
double x = 0.5 ;
for (int j = 0 ; j < 100 ; j++) {
x = lambda * x * (1-x);
}
for (int j = 0 ; j < 50; j++) {
Data<Number, Number> data = new Data<>(lambda, x);
Region plotpoint = new Region();
plotpoint.setShape(new Circle(0.5));
data.setNode(plotpoint);
series.getData().add(data);
x = lambda * x * (1-x);
}
}
Run Code Online (Sandbox Code Playgroud)
和 CSS
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.ScatterChart;
import javafx.scene.chart.XYChart.Data;
import javafx.scene.chart.XYChart.Series;
import javafx.stage.Stage;
public class ScatterChartExample extends Application {
@Override
public void start(Stage primaryStage) {
ScatterChart<Number, Number> chart = new ScatterChart<>(new NumberAxis(), new NumberAxis());
chart.setId("bifurcation-diagram");
Series<Number, Number> series = new Series<>();
chart.getData().add(series);
for (int i = 0 ; i <= 100; i++) {
double lambda = 4.0 * i / 100 ;
double x = 0.5 ;
for (int j = 0 ; j < 100 ; j++) {
x = lambda * x * (1-x);
}
for (int j = 0 ; j < 50; j++) {
series.getData().add(new Data<>(lambda, x));
x = lambda * x * (1-x);
}
}
Scene scene = new Scene(chart, 1200, 800);
scene.getStylesheets().add("bifurcation.css");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3059 次 |
| 最近记录: |