本文整理汇总了Java中javafx.scene.chart.XYChart.setData方法的典型用法代码示例。如果您正苦于以下问题:Java XYChart.setData方法的具体用法?Java XYChart.setData怎么用?Java XYChart.setData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javafx.scene.chart.XYChart
的用法示例。
在下文中一共展示了XYChart.setData方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addDataItemStrNum
import javafx.scene.chart.XYChart; //导入方法依赖的package包/类
public static void addDataItemStrNum(final XYChart<String, Number> chart) {
if (chart.getData() == null) {
chart.setData(FXCollections.<XYChart.Series<String, Number>>observableArrayList());
}
if (chart.getData().isEmpty()) {
chart.getData().add(new XYChart.Series<String, Number>());
}
int sIndex = (int) (Math.random() * chart.getData().size());
XYChart.Series<String, Number> series = chart.getData().get(sIndex);
Set<String> existingYears = new HashSet<String>();
for (Data<String, Number> data : series.getData()) {
existingYears.add(data.getXValue());
}
int randomYear = 1900 + (int) (Math.round(12 * Math.random()) * 10);
while (existingYears.contains(Integer.toString(randomYear))) {
randomYear++;
}
series.getData().add(new XYChart.Data<String, Number>(Integer.toString(randomYear), 10 + (Math.random() * 3800)));
}
示例2: addDataItemNumStr
import javafx.scene.chart.XYChart; //导入方法依赖的package包/类
public static void addDataItemNumStr(final XYChart<Number, String> chart) {
if (chart.getData() == null) {
chart.setData(FXCollections.<XYChart.Series<Number, String>>observableArrayList());
}
if (chart.getData().isEmpty()) {
chart.getData().add(new XYChart.Series<Number, String>());
}
int sIndex = (int) (Math.random() * chart.getData().size());
XYChart.Series<Number, String> series = chart.getData().get(sIndex);
Set<String> existingYears = new HashSet<String>();
for (Data<Number, String> data : series.getData()) {
existingYears.add(data.getYValue());
}
int randomYear = 1900 + (int) (Math.round(12 * Math.random()) * 10);
while (existingYears.contains(Integer.toString(randomYear))) {
randomYear++;
}
series.getData().add(new XYChart.Data<Number, String>(10 + (Math.random() * 3800), Integer.toString(randomYear)));
}