javafx - 获取折线图系列描边颜色
问题描述
这是对这个问题的跟进:如何从 JavaFX 图表中的系列中获取颜色并将其分配给具有 0 个答案的复选框。
我想获取我的 LineChart 系列笔划生成的颜色,以便将其设置为复选框的文本颜色。
这是我的示例代码(取自 Oracle 教程的折线图):
public class LineChartSample extends Application {
@Override
public void start(Stage stage) {
HBox box = new HBox();
stage.setTitle("Line Chart Sample");
final NumberAxis xAxis = new NumberAxis();
final NumberAxis yAxis = new NumberAxis();
xAxis.setLabel("Number of Month");
final LineChart<Number, Number> lineChart = new LineChart<Number, Number>(xAxis, yAxis);
lineChart.setTitle("Stock Monitoring, 2010");
XYChart.Series series = new XYChart.Series();
series.setName("My portfolio");
series.getData().add(new XYChart.Data(1, 23));
series.getData().add(new XYChart.Data(2, 14));
series.getData().add(new XYChart.Data(3, 15));
series.getData().add(new XYChart.Data(4, 24));
series.getData().add(new XYChart.Data(5, 34));
series.getData().add(new XYChart.Data(6, 36));
series.getData().add(new XYChart.Data(7, 22));
series.getData().add(new XYChart.Data(8, 45));
series.getData().add(new XYChart.Data(9, 43));
series.getData().add(new XYChart.Data(10, 17));
series.getData().add(new XYChart.Data(11, 29));
series.getData().add(new XYChart.Data(12, 25));
lineChart.getData().add(series);
CheckBox test = new CheckBox("test");
test.setStyle("-fx-text-fill: <series color>;");
box.getChildren().addAll(lineChart, test);
Scene scene = new Scene(box, 800, 600);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
我尝试将系列样式类添加到复选框样式类中(如从 LineChart 获取系列颜色中所建议的那样):
test.getStyleClass().addAll(series.getNode().getStyleClass());
其中系列样式类是一个包含以下值的列表:chart-series-line、series0 和 default-color0,但它不起作用。
在此先感谢您的帮助。
解决方案
推荐阅读
- spring - 在 Spring SFTP 上设置首选身份验证方法
- c# - 启用 Windows 2008 R2 以接受对枚举 SslProtocols 3072 的强制转换
- ruby-on-rails - 在 rails number_field 中舍入
- go - 类型开关未检测到 float32
- javascript - Redux 商店不更新状态更改的组件视图
- java - 如何在 Kotlin 的 Main Activity 中打开多个活动?
- jquery - 在加载器后的新 href 上以加载器样式定位 src 属性图像
- maven - 即使提供了范围,为什么 maven 还要添加依赖库?
- javascript - 在 JavaScript 中 call() 是同步的,而 apply() 是异步的?
- sql - 如何在 SQL 中按句点将文本拆分为列?