本文整理汇总了Java中javafx.scene.chart.CategoryAxis.setCategories方法的典型用法代码示例。如果您正苦于以下问题:Java CategoryAxis.setCategories方法的具体用法?Java CategoryAxis.setCategories怎么用?Java CategoryAxis.setCategories使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javafx.scene.chart.CategoryAxis
的用法示例。
在下文中一共展示了CategoryAxis.setCategories方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createBarChart
import javafx.scene.chart.CategoryAxis; //导入方法依赖的package包/类
private BarChart createBarChart() {
CategoryAxis xAxis = new CategoryAxis();
xAxis.setCategories(FXCollections.<String>observableArrayList(tableModel.getColumnNames()));
xAxis.setLabel("Year");
double tickUnit = tableModel.getTickUnit();
NumberAxis yAxis = new NumberAxis();
yAxis.setTickUnit(tickUnit);
yAxis.setLabel("Units Sold");
final BarChart chart = new BarChart(xAxis, yAxis, tableModel.getBarChartData());
tableModel.addTableModelListener(new TableModelListener() {
public void tableChanged(TableModelEvent e) {
if (e.getType() == TableModelEvent.UPDATE) {
final int row = e.getFirstRow();
final int column = e.getColumn();
final Object value = ((SampleTableModel) e.getSource()).getValueAt(row, column);
Platform.runLater(new Runnable() {
public void run() {
XYChart.Series<String, Number> s = (XYChart.Series<String, Number>) chart.getData().get(row);
BarChart.Data data = s.getData().get(column);
data.setYValue(value);
}
});
}
}
});
return chart;
}
示例2: BarChartSample
import javafx.scene.chart.CategoryAxis; //导入方法依赖的package包/类
public BarChartSample() {
String[] years = {"2007", "2008", "2009"};
CategoryAxis xAxis = new CategoryAxis();
xAxis.setCategories(FXCollections.<String>observableArrayList(years));
NumberAxis yAxis = new NumberAxis("Units Sold", 0.0d, 3000.0d, 1000.0d);
ObservableList<BarChart.Series> barChartData = FXCollections.observableArrayList(
new BarChart.Series("Apples", FXCollections.observableArrayList(
new BarChart.Data(years[0], 567d),
new BarChart.Data(years[1], 1292d),
new BarChart.Data(years[2], 1292d)
)),
new BarChart.Series("Lemons", FXCollections.observableArrayList(
new BarChart.Data(years[0], 956),
new BarChart.Data(years[1], 1665),
new BarChart.Data(years[2], 2559)
)),
new BarChart.Series("Oranges", FXCollections.observableArrayList(
new BarChart.Data(years[0], 1154),
new BarChart.Data(years[1], 1927),
new BarChart.Data(years[2], 2774)
))
);
BarChart chart = new BarChart(xAxis, yAxis, barChartData, 25.0d);
getChildren().add(chart);
}
示例3: createChart
import javafx.scene.chart.CategoryAxis; //导入方法依赖的package包/类
protected BarChart<String, Number> createChart() {
final String[] years = {"2007", "2008", "2009"};
final CategoryAxis xAxis = new CategoryAxis();
final NumberAxis yAxis = new NumberAxis();
yAxis.setTickLabelFormatter(new NumberAxis.DefaultFormatter(yAxis,"$",null));
final BarChart<String,Number> bc = new BarChart<String,Number>(xAxis,yAxis);
// setup chart
bc.setTitle("Advanced Bar Chart");
xAxis.setLabel("Year");
xAxis.setCategories(FXCollections.<String>observableArrayList(Arrays.asList(years)));
yAxis.setLabel("Price");
// add starting data
XYChart.Series<String,Number> series1 = new XYChart.Series<String,Number>();
series1.setName("Data Series 1");
XYChart.Series<String,Number> series2 = new XYChart.Series<String,Number>();
series2.setName("Data Series 2");
XYChart.Series<String,Number> series3 = new XYChart.Series<String,Number>();
series3.setName("Data Series 3");
// create sample data
series1.getData().add(new XYChart.Data<String,Number>(years[0], 567));
series1.getData().add(new XYChart.Data<String,Number>(years[1], 1292));
series1.getData().add(new XYChart.Data<String,Number>(years[2], 2180));
series2.getData().add(new XYChart.Data<String,Number>(years[0], 956));
series2.getData().add(new XYChart.Data<String,Number>(years[1], 1665));
series2.getData().add(new XYChart.Data<String,Number>(years[2], 2450));
series3.getData().add(new XYChart.Data<String,Number>(years[0], 800));
series3.getData().add(new XYChart.Data<String,Number>(years[1], 1000));
series3.getData().add(new XYChart.Data<String,Number>(years[2], 2800));
bc.getData().add(series1);
bc.getData().add(series2);
bc.getData().add(series3);
return bc;
}
示例4: createChart
import javafx.scene.chart.CategoryAxis; //导入方法依赖的package包/类
protected BarChart<Number, String> createChart() {
final String[] years = {"2007", "2008", "2009"};
final CategoryAxis yAxis = new CategoryAxis();
final NumberAxis xAxis = new NumberAxis();
final BarChart<Number,String> bc = new BarChart<Number,String>(xAxis,yAxis);
// setup chart
bc.setTitle("Horizontal Bar Chart Example");
yAxis.setLabel("Year");
yAxis.setCategories(FXCollections.<String>observableArrayList(Arrays.asList(years)));
xAxis.setLabel("Price");
// add starting data
XYChart.Series<Number,String> series1 = new XYChart.Series<Number,String>();
series1.setName("Data Series 1");
XYChart.Series<Number,String> series2 = new XYChart.Series<Number,String>();
series2.setName("Data Series 2");
XYChart.Series<Number,String> series3 = new XYChart.Series<Number,String>();
series3.setName("Data Series 3");
series1.getData().add(new XYChart.Data<Number,String>(567, years[0]));
series1.getData().add(new XYChart.Data<Number,String>(1292, years[1]));
series1.getData().add(new XYChart.Data<Number,String>(2180, years[2]));
series2.getData().add(new XYChart.Data<Number,String>(956, years[0]));
series2.getData().add(new XYChart.Data<Number,String>(1665, years[1]));
series2.getData().add(new XYChart.Data<Number,String>(2450, years[2]));
series3.getData().add(new XYChart.Data<Number,String>(800, years[0]));
series3.getData().add(new XYChart.Data<Number,String>(1000, years[1]));
series3.getData().add(new XYChart.Data<Number,String>(2800, years[2]));
bc.getData().add(series1);
bc.getData().add(series2);
bc.getData().add(series3);
return bc;
}
示例5: prepareXAxis
import javafx.scene.chart.CategoryAxis; //导入方法依赖的package包/类
/**
* This method is a little weird, but necessary, due to the quirks of JavaFX charts.
*
* Essentially, the problem boils down to the fact that JavaFX charts cannot cleanly handle
* an integer based axis in exactly the way we need them to, so we have to hack around it by
* using categories whose names just happen to be the integer days of the month.
*/
private void prepareXAxis() {
int selectedYear = selectedMonth.getYear();
int numDaysInMonth = selectedMonth.getMonth().length(Year.isLeap(selectedYear));
for(int i = 1; i <= numDaysInMonth; i++) {
daysInCurrentMonth.add(String.valueOf(i));
}
CategoryAxis xAxis = (CategoryAxis) lineChart.getXAxis();
xAxis.setCategories(daysInCurrentMonth);
}
示例6: TimingDiagramController
import javafx.scene.chart.CategoryAxis; //导入方法依赖的package包/类
/**
* Instantiates a new Timing diagram controller with a category xAxis.
*
* @param commonXAxis the common x axis
* @param externalYAxis the external y axis
* @param spec the specification
* @param ioVariable the io variable
* @param selection the selection that should be updated
* @param activated property that indicates if the selection should be updated
*/
public TimingDiagramController(NumberAxis commonXAxis, CategoryAxis externalYAxis,
ConcreteSpecification spec, ValidIoVariable ioVariable, Selection selection,
BooleanProperty activated) {
this.activated = activated;
this.ioVariable = ioVariable;
this.selection = selection;
this.concreteSpec = spec;
this.commonXAxis = commonXAxis;
NumberAxis xaxis = new NumberAxis(0, 0, 1);
CategoryAxis yaxis = new CategoryAxis();
TimingDiagramView<String> view = new TimingDiagramView<>(xaxis, yaxis);
this.view = view;
XYChart.Series<Number, String> seriesData =
Plotable.toStringSeries(spec.getColumnByName(ioVariable.getName()).getCells());
ObservableList<XYChart.Series<Number, String>> data = FXCollections.observableArrayList();
data.add(seriesData);
view.getData().addAll(data);
externalYAxis.prefHeightProperty().bind(yaxis.heightProperty());
yaxis.setAutoRanging(true);
yaxis.setCategories(externalYAxis.getCategories());
xaxis.lowerBoundProperty().bind(commonXAxis.lowerBoundProperty());
xaxis.upperBoundProperty().bind(commonXAxis.upperBoundProperty());
initCommon();
}
示例7: getResultsContent
import javafx.scene.chart.CategoryAxis; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Parent getResultsContent() {
NumberAxis xAxis = new NumberAxis();
CategoryAxis yAxis = new CategoryAxis();
BarChart<Number, String> chart = new BarChart<>(xAxis, yAxis);
chart.setTitle("Data structure packet size based on number of packets");
yAxis.setLabel("Number of Packets");
yAxis.setCategories(FXCollections.<String>observableArrayList(Arrays.asList(new String[] {String.valueOf(numPackets)})));
xAxis.setLabel("Size (in bytes). Lower is better");
for (int i = 0; i < results.size(); i++) {
XYChart.Series<Number, String> series = new XYChart.Series<Number, String>();
series.setName(results.get(i).name);
series.getData().addAll(
new XYChart.Data<Number, String>(results.get(i).size, String.valueOf(numPackets))
// new XYChart.Data<Number, String>(results1000.get(i).size, "1000"),
// new XYChart.Data<Number, String>(results10000.get(i).size, "10000")
);
series.getData().forEach(data -> {
Label l = new Label(data.getXValue().toString());
l.setAlignment(Pos.CENTER_RIGHT);
data.setNode(l);
});
chart.getData().add(series);
}
return chart;
}
示例8: getResultsContent
import javafx.scene.chart.CategoryAxis; //导入方法依赖的package包/类
@Override
public Parent getResultsContent() {
NumberAxis xAxis = new NumberAxis();
CategoryAxis yAxis = new CategoryAxis();
BarChart<Number, String> chart = new BarChart<>(xAxis, yAxis);
chart.setTitle(String.valueOf(numPackets) + " packets");
yAxis.setLabel("Compression");
yAxis.setCategories(FXCollections.<String>observableArrayList("NONE", "ZIP", "LZMA"));
xAxis.setLabel("Time (in seconds). Lower is better");
for (int i = 0; i < results.size(); i++) {
XYChart.Series<Number, String> series = new XYChart.Series<Number, String>();
series.setName(results.get(i).name);
series.getData().addAll(
new XYChart.Data<Number, String>(results.get(i).timeTook, "NONE"),
new XYChart.Data<Number, String>(results.get(i).timeTookZIP + results.get(i).timeTook, "ZIP"),
new XYChart.Data<Number, String>(results.get(i).timeTookLZMA + results.get(i).timeTook, "LZMA")
);
series.getData().forEach(data -> {
Label l = new Label(String.format("%.3f", data.getXValue().doubleValue()));
l.setAlignment(Pos.CENTER_RIGHT);
data.setNode(l);
});
chart.getData().add(series);
}
return chart;
}
示例9: getResultsContent
import javafx.scene.chart.CategoryAxis; //导入方法依赖的package包/类
@Override
public Parent getResultsContent() {
NumberAxis xAxis = new NumberAxis();
CategoryAxis yAxis = new CategoryAxis();
BarChart<Number, String> chart = new BarChart<>(xAxis, yAxis);
chart.setTitle("Data structure packet size based on number of packets");
yAxis.setLabel("Number of Packets");
yAxis.setCategories(FXCollections.<String>observableArrayList(Arrays.asList(new String[] {String.valueOf(numPackets)})));
xAxis.setLabel("Speed (in seconds). Lower is better");
for (int i = 0; i < results.size(); i++) {
XYChart.Series<Number, String> series = new XYChart.Series<Number, String>();
series.setName(results.get(i).name);
series.getData().addAll(
new XYChart.Data<Number, String>(results.get(i).timeTook, String.valueOf(numPackets))
// new XYChart.Data<Number, String>(results1000.get(i).size, "1000"),
// new XYChart.Data<Number, String>(results10000.get(i).size, "10000")
);
series.getData().forEach(data -> {
Label l = new Label(data.getXValue().toString());
l.setAlignment(Pos.CENTER_RIGHT);
data.setNode(l);
});
chart.getData().add(series);
}
return chart;
}
示例10: getResultsContent
import javafx.scene.chart.CategoryAxis; //导入方法依赖的package包/类
@Override
public Parent getResultsContent() {
NumberAxis xAxis = new NumberAxis();
CategoryAxis yAxis = new CategoryAxis();
BarChart<Number, String> chart = new BarChart<>(xAxis, yAxis);
chart.setTitle(String.valueOf(numPackets) + " packets");
yAxis.setLabel("Compression");
yAxis.setCategories(FXCollections.<String>observableArrayList("NONE", "ZIP", "LZMA"));
xAxis.setLabel("Size (in bytes). Lower is better");
for (int i = 0; i < results.size(); i++) {
XYChart.Series<Number, String> series = new XYChart.Series<Number, String>();
series.setName(results.get(i).name);
series.getData().addAll(
new XYChart.Data<Number, String>(results.get(i).size, "NONE"),
new XYChart.Data<Number, String>(results.get(i).sizeCompressedZIP, "ZIP"),
new XYChart.Data<Number, String>(results.get(i).sizeCompressedLZMA, "LZMA")
);
series.getData().forEach(data -> {
Label l = new Label(data.getXValue().toString());
l.setAlignment(Pos.CENTER_RIGHT);
data.setNode(l);
});
chart.getData().add(series);
}
return chart;
}
示例11: drawNode
import javafx.scene.chart.CategoryAxis; //导入方法依赖的package包/类
@Override
public Node drawNode() {
CategoryAxis axis = new CategoryAxis();
axis.setCategories(FXCollections.<String>observableArrayList("First", "Second", "Third"));
return axis;
}