gpt4 book ai didi

JavaFx - 以编程方式设置折线图系列颜色

转载 作者:搜寻专家 更新时间:2023-11-01 03:54:07 27 4
gpt4 key购买 nike

我是 Java 的新手,也是 JavaFX 的新手。我正在尝试构建一个使用 JavaFx LineChart 显示实时数据的动态图。

我在 oracle 文档中注意到 http://docs.oracle.com/javafx/2/charts/css-styles.htm#CIHGIAGE图表可以使用 CSS 设置样式。

是否可以通过编程方式更改系列的颜色?

public Node addLineChart(){

//final NumberAxis yAxis = new NumberAxis(-80,60,20);
final NumberAxis yAxis;
final CategoryAxis xAxis;

if(firingOrderSelectionIndex >= 0){
String selectedFiringOrder = firingOrders[cylselectionIndex][firingOrderSelectionIndex];
String[] currentFiringOrder = selectedFiringOrder.split("-");

xAxis = new CategoryAxis(FXCollections.observableArrayList(currentFiringOrder));
xAxis.setAutoRanging(false);

if(selectionIndex > 1){
yAxis = new NumberAxis(-60,40,20);
}else{
yAxis = new NumberAxis(-75,50,15);
}
}else{
xAxis = new CategoryAxis();
yAxis = new NumberAxis(0,0,0);
}

xAxis.setLabel("Order");
xAxis.setStyle("-fx-font-size: 14;-fx-font-weight: bolder;");
//xAxis.setAutoRanging(false); //If you are manually setting values in the constructor you can do this.
//otherwise if this is done, the graph will crash. So, while using constructor with no values leave this config as default.

//xAxis.setLowerBound(1);
//xAxis.setUpperBound(4);
//xAxis.setTickUnit(1);

yAxis.setMinorTickVisible(false);

final LineChart<String,Number> lineChart = new LineChart<String,Number>(xAxis,yAxis);
lineChart.setTitle("Graph");
lineChart.setLegendVisible(false);
lineChart.setStyle(".default-color0.chart-series-line { -fx-stroke: #f0e68c; }");

//series.setName("Live");
series.getData().add(new XYChart.Data("1", 5));
series.getData().add(new XYChart.Data("2", 5));

lineChart.getData().add(series);
xAxis.setVisible(false);

return lineChart;
}

最佳答案

chart.setStyle(".default-color0.chart-series-line { -fx-stroke: #e9967a; }");

关于JavaFx - 以编程方式设置折线图系列颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13964453/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com