我是Java新手,對JavaFX也是如此。我正在嘗試構建一個使用JavaFx LineChart顯示實時數據的動態圖。JavaFx - 以編程方式設置LineChart系列顏色
我注意到在oracle docs 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;
}
可能重複的[如何動態改變線條樣式中的JavaFX 2.0線圖?](http://stackoverflow.com/questions/9757848/how-to-dynamically-change-line-style -in-javafx-2-0-line-chart) – jewelsea