如何设置条形图的笔触(颜色)?我总是有黄条
这是我的代码
import java.util.Set;
import javafx.application.Application;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.chart.BarChart;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class StackPaneTest extends Application {
@Override
public void start(Stage primaryStage) {
final CategoryAxis xAxis1 = new CategoryAxis();
final NumberAxis yAxis1 = new NumberAxis();
final BarChart<String, Number> barChart = new BarChart<String, Number>(xAxis1, yAxis1);
barChart.setAlternativeRowFillVisible(false);
barChart.setLegendVisible(false);
barChart.setAnimated(false);
XYChart.Series serie1 = new XYChart.Series();
serie1.getData().add(new XYChart.Data("Jan", 1));
serie1.getData().add(new XYChart.Data("Feb", 2));
serie1.getData().add(new XYChart.Data("Mar", 1.5));
serie1.getData().add(new XYChart.Data("Apr", 3));
serie1.getData().add(new XYChart.Data("May", 2.5));
serie1.getData().add(new XYChart.Data("Jun", 5));
serie1.getData().add(new XYChart.Data("Jul", 4));
serie1.getData().add(new XYChart.Data("Aug", 8));
serie1.getData().add(new XYChart.Data("Sep", 6.5));
serie1.getData().add(new XYChart.Data("Oct", 13));
serie1.getData().add(new XYChart.Data("Nov", 10));
serie1.getData().add(new XYChart.Data("Dec", 20));
barChart.getData().addAll(serie1);
Set<Node> barNode = barChart.lookupAll(".default-color0.chart-bar");
for(final Node bar : barNode){
bar.setStyle("-fx-stroke: GREEN");
}
StackPane stack = new StackPane();
stack.getChildren().addAll(barChart);
Scene scene = new Scene(stack, 800, 600);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}