在JavaFx中的条形下定位xAxis值

时间:2015-04-07 22:22:05

标签: javafx bar-chart

我正在创建一个条形图,你可以在照片中看到。问题是XAxis上的条形名称与条形图的不匹配程度。 刻度标签旋转在fxml中设置为-45。我怎样才能将它们准确地移到吧台下? bar

public class MostComputerizedController {
@FXML
private BarChart<String, Number> barChart;
@FXML
private CategoryAxis orgNameAxis;
@FXML
private NumberAxis yAxis;
@FXML
private Label itsfField;

private ObservableList<String> orgNames = FXCollections
        .observableArrayList();
private DataConstructor dc = new DataConstructor();
private int numberOfOrganizations;
private List<Double> sumOfOrgsITSF = new ArrayList<Double>();

/**
 * sets the name of x axis, with the name of organizations
 */
@FXML
private void initialize() {
    dc.findSortedAssignedOrg();
    dc.orgFuncFuncType();
    orgNames.addAll(dc.getOrgFuncFunctype().keySet());
    orgNameAxis.setCategories(orgNames);

    orgNameAxis.setLabel("Name of Organizations");
    orgNameAxis.tickLabelFontProperty().set(Font.font(9));
    yAxis.setLabel("Saturation");
    numberOfOrganizations = dc.getSortedAssignedOrg().size();

}

/**
 * sets organization and their saturation
 */
public void setOrgData() {
    XYChart.Series<String, Number> seriesGreen = new XYChart.Series<>();
    XYChart.Series<String, Number> seriesYellow = new XYChart.Series<>();
    seriesGreen.setName("IT Saturation Satisfying");
    seriesYellow.setName("IT Saturation not Satisfying");
    for (Entry<String, List<Double>> entry : dc.getOrgFuncFunctype()
            .entrySet()) {
        sumOfOrgsITSF.add(entry.getValue().get(0));
        if (entry.getValue().get(0) > 50) {
            seriesGreen.getData().add(
                    new XYChart.Data<String, Number>(entry.getKey(), entry
                            .getValue().get(0)));
        } else if ((entry.getValue().get(0) <= 50)) {
            seriesYellow.getData().add(
                    new XYChart.Data<String, Number>(entry.getKey(), entry
                            .getValue().get(0)));
        }

    }

    double value = sumOfOrgsITSF.stream().mapToDouble(Double::doubleValue)
            .sum()
            / numberOfOrganizations;
    itsfField.setText(String.format("%.0f", value) + "%");
    barChart.setBarGap(1);
    barChart.setCategoryGap(10);
    barChart.getData().addAll(seriesGreen, seriesYellow);
}

1 个答案:

答案 0 :(得分:0)

将所有数据放在一个序列中。

series1.getData().add(new Data<Number, String>(Integer1),(Title1)));
series1.getData().add(new Data<Number, String>(Integer2),(Title2)));
series1.getData().add(new Data<Number, String>(Integer3),(Title3)));

结果: enter image description here