这是我的代码,它生成从 0 到 10 的 10 个值的条形图。我想改变条的颜色如下
如果 i>5 颜色==红色 如果 i>8 颜色==蓝色
所以最终出局将是 0-5(默认黄色条) 6-8(红色条) 9(蓝色条)
请帮助我..谢谢
public class BarChartSample extends Application {
@Override
public void start(Stage stage) {
stage.setTitle("Bar Chart Sample");
final CategoryAxis xAxis = new CategoryAxis();
final NumberAxis yAxis = new NumberAxis();
final BarChart < String, Number > bc = new BarChart < String, Number > (xAxis, yAxis);
bc.setTitle("Country Summary");
xAxis.setLabel("bars");
yAxis.setLabel("Value");
XYChart.Series series1 = new XYChart.Series();
series1.setName("...");
for (int i = 0; i < 10; i++) {
//here i want to change color of bar if value of i is >5 than red if i>8 than blue
series1.getData().add(new XYChart.Data("Value", i));
}
}
public static void main(String[] args) {
launch(args);
}
}