如何使用Javafx更改条形图中的条形颜色

时间:2015-03-22 22:42:50

标签: javafx bar-chart

我需要更改条形图中条形的颜色。我不想使用额外的css文件。有没有一种方法可以在代码中执行此操作?

...
@FXML
private void initialize(){

    orgNames.addAll(dc.getSortedAssignedOrg().values());
    orgNameAxis.setCategories(orgNames);
    orgNameAxis.setLabel("Name of Organizations");
    orgNameAxis.tickLabelFontProperty().set(Font.font(10));
    yAxis.setLabel("Saturation");
}
 public void setPersonData() {
    XYChart.Series<String, Number> series  = new XYChart.Series<>();

   for ( String entryOrg : dc.getSortedAssignedOrg().values()) {
       for(List<String> entryfuncType : dc.getFuncTypeOrg().values()){
           if(entryOrg.equals(entryfuncType.get(5)) && entryfuncType.contains("hasType")){
            int yellow =   Collections.frequency(
                       entryfuncType, "yellow");
            int green = Collections.frequency(entryfuncType, "Green");
            int typeNumber = Collections.frequency(entryfuncType, "hasType");
            float sat = (Float.parseFloat((entryfuncType.get(2))) * green )/ typeNumber;
            //change color
              series.getData().add(new XYChart.Data<String,Number>(entryOrg, sat));

           }
       }

   }

   barChart.getData().add(series);
   }

0 个答案:

没有答案