我有一个可能具有空值的图表,我也想要修复X轴比例(ex.20点)。 和绑定到Y轴的值(非空值ex.10值)。
[更新]
String [] categories = {"32-11, 33-11, 34-11, 35-11, 36-11, 37-11, 38-11, 39-11, 40-11, 41-11, 42-11, 43-11, 44-11, 45-11, 46-11, 47-11, 48-11, 49-11, 50-11, 51-11"};
LineChart<String, Number> myChart;
CategoryAxis xAxis;
NumberAxis yAxis;
yAxis = new NumberAxis();
xAxis = new CategoryAxis();
xAxis.setCategories(FXCollections.<String>observableArrayList(Arrays.asList(categories)));
xAxis.setAutoRanging(false);
myChart = new LineChart<String, Number>(xAxis,yAxis);
Series<String, Number> aSeries = new Series<String, Number>();
for (int i = 0; i < categories.length; i++) {
aSeries.getData().add(new XYChart.Data(categories[i],"Some Long values and may be null"));
}
myChart.getData().add(aSeries);
答案 0 :(得分:3)
然后添加一行就行了。
public final void setCategories(ObservableList<String> value) {
categories.set(value);
invalidateRange(value); //add that line
requestAxisLayout();
}
<强>更新强>
问题可以在不改变CategoryAxis类的情况下解决,只需将该行添加到我的代码中:
xAxis.setAutoRanging(false);
xAxis.setCategories(FXCollections.<String>observableArrayList(Arrays.asList(categories)));
xAxis.invalidateRange(Arrays.asList(categories)); // add that line to my code.