Java Code Examples for javafx.scene.chart.CategoryAxis

The following are top voted examples for showing how to use javafx.scene.chart.CategoryAxis. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: marathonv5   File: SwingInterop.java   View source code 7 votes vote down vote up
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;
}
 
Example 2
Project: marathonv5   File: AdvLineCategoryChartSample.java   View source code 6 votes vote down vote up
protected LineChart<String, Number> createChart() {
    final CategoryAxis xAxis = new CategoryAxis();
    final NumberAxis yAxis = new NumberAxis();
    final LineChart<String,Number> lc = new LineChart<String,Number>(xAxis,yAxis);
    // setup chart
    lc.setTitle("LineChart with Category Axis");
    xAxis.setLabel("X Axis");
    yAxis.setLabel("Y Axis");
    // add starting data
    XYChart.Series<String,Number> series = new XYChart.Series<String,Number>();
    series.setName("Data Series 1");
    series.getData().add(new XYChart.Data<String,Number>(CATEGORIES[0], 50d));
    series.getData().add(new XYChart.Data<String,Number>(CATEGORIES[1], 80d));
    series.getData().add(new XYChart.Data<String,Number>(CATEGORIES[2], 90d));
    series.getData().add(new XYChart.Data<String,Number>(CATEGORIES[3], 30d));
    series.getData().add(new XYChart.Data<String,Number>(CATEGORIES[4], 122d));
    series.getData().add(new XYChart.Data<String,Number>(CATEGORIES[5], 10d));
    lc.getData().add(series);
    return lc;
}
 
Example 3
Project: marathonv5   File: BarChartSample.java   View source code 6 votes vote down vote up
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);
}
 
Example 4
Project: marathonv5   File: ImageBarChartSample.java   View source code 6 votes vote down vote up
public ImageBarChartSample() {

        String imageBarChartCss = ImageBarChartSample.class.getResource("ImageBarChart.css").toExternalForm();

        BarChart barChart = new BarChart(new CategoryAxis(), new NumberAxis());
        barChart.setLegendVisible(false);
        barChart.getStylesheets().add(imageBarChartCss);

        barChart.getData().add(
                new XYChart.Series<String, Integer>("Sales Per Product",
                FXCollections.observableArrayList(
                new XYChart.Data<String, Integer>("SUV", 120),
                new XYChart.Data<String, Integer>("Sedan", 50),
                new XYChart.Data<String, Integer>("Truck", 180),
                new XYChart.Data<String, Integer>("Van", 20))));

        Scene scene = new Scene(barChart, 350, 300);
        scene.getStylesheets().add(ImageBarChartSample.class.getResource("ImageBarChart.css").toString());
        getChildren().add(barChart);
    }
 
Example 5
Project: marathonv5   File: AdvLineCategoryChartSample.java   View source code 6 votes vote down vote up
protected LineChart<String, Number> createChart() {
    final CategoryAxis xAxis = new CategoryAxis();
    final NumberAxis yAxis = new NumberAxis();
    final LineChart<String,Number> lc = new LineChart<String,Number>(xAxis,yAxis);
    // setup chart
    lc.setTitle("LineChart with Category Axis");
    xAxis.setLabel("X Axis");
    yAxis.setLabel("Y Axis");
    // add starting data
    XYChart.Series<String,Number> series = new XYChart.Series<String,Number>();
    series.setName("Data Series 1");
    series.getData().add(new XYChart.Data<String,Number>(CATEGORIES[0], 50d));
    series.getData().add(new XYChart.Data<String,Number>(CATEGORIES[1], 80d));
    series.getData().add(new XYChart.Data<String,Number>(CATEGORIES[2], 90d));
    series.getData().add(new XYChart.Data<String,Number>(CATEGORIES[3], 30d));
    series.getData().add(new XYChart.Data<String,Number>(CATEGORIES[4], 122d));
    series.getData().add(new XYChart.Data<String,Number>(CATEGORIES[5], 10d));
    lc.getData().add(series);
    return lc;
}
 
Example 6
Project: marathonv5   File: BarChartSample.java   View source code 6 votes vote down vote up
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);
}
 
Example 7
Project: marathonv5   File: ImageBarChartSample.java   View source code 6 votes vote down vote up
public ImageBarChartSample() {

        String imageBarChartCss = ImageBarChartSample.class.getResource("ImageBarChart.css").toExternalForm();

        BarChart barChart = new BarChart(new CategoryAxis(), new NumberAxis());
        barChart.setLegendVisible(false);
        barChart.getStylesheets().add(imageBarChartCss);

        barChart.getData().add(
                new XYChart.Series<String, Integer>("Sales Per Product",
                FXCollections.observableArrayList(
                new XYChart.Data<String, Integer>("SUV", 120),
                new XYChart.Data<String, Integer>("Sedan", 50),
                new XYChart.Data<String, Integer>("Truck", 180),
                new XYChart.Data<String, Integer>("Van", 20))));

        Scene scene = new Scene(barChart, 350, 300);
        scene.getStylesheets().add(ImageBarChartSample.class.getResource("ImageBarChart.css").toString());
        getChildren().add(barChart);
    }
 
Example 8
Project: Gargoyle   File: GoogleTrendExam.java   View source code 6 votes vote down vote up
@Override
public void start(Stage primaryStage) throws Exception {

	URL url = new URL(createUrl());

	String jsonString = RequestUtil.requestSSL(url, requestHandler);

	//		String source = ValueUtil.toString(GoogleTrendExam.class.getResourceAsStream("GoogleTrendSample.json"));
	BaseGoogleTrendChart root = new BaseGoogleTrendChart(jsonString, new CategoryAxis(), new NumberAxis(0, 100, 10));
	root.setVerticalGridLinesVisible(false);
	root.addEventFilter(GoogleTrendChartEvent.GOOGLE_CHART_INTERSECT_NODE_CLICK, ev -> {
		System.out.println(ev.getContents());
	});

	root.addEventHandler(GoogleTrendChartEvent.GOOGLE_CHART_INTERSECT_NODE_CLICK, ev -> {
		System.out.println(ev.getContents());
	});
	primaryStage.setScene(new Scene(root));
	primaryStage.show();
}
 
Example 9
Project: Gargoyle   File: AbstractGoogleTrendChart.java   View source code 6 votes vote down vote up
public AbstractGoogleTrendChart(String source, CategoryAxis x, NumberAxis y) {
	super(x, y);

	this.source.set(source);
	this.adapter = adapter();

	Platform.runLater(() -> {
		fillChartData();
		action();
	});

	this.source.addListener((oba, o, n) -> {

		if (ValueUtil.isNotEmpty(n)) {
			this.json.set(convert(n));
			clearChartData();
			fillChartData();
		}

	});
}
 
Example 10
Project: zest-writer   File: MenuController.java   View source code 6 votes vote down vote up
private void displayIndex(Map<String, Double> resultIndex, String title, String header) {
    BaseDialog dialog = new BaseDialog(title, header);
    dialog.getDialogPane().setPrefSize(800, 600);
    dialog.getDialogPane().getButtonTypes().addAll(new ButtonType(Configuration.getBundle().getString("ui.actions.stats.close"), ButtonBar.ButtonData.CANCEL_CLOSE));

    // draw
    final CategoryAxis xAxis = new CategoryAxis();
    final NumberAxis yAxis = new NumberAxis();
    final LineChart<String,Number> lineChart = new LineChart<>(xAxis, yAxis);
    lineChart.setTitle(title);
    lineChart.setLegendVisible(false);

    xAxis.setLabel(Configuration.getBundle().getString("ui.actions.stats.xaxis"));
    yAxis.setLabel(Configuration.getBundle().getString("ui.actions.readable.yaxis"));

    XYChart.Series<String, Number> series = new XYChart.Series();
    for(Map.Entry<String, Double> st:resultIndex.entrySet()) {
        series.getData().add(new XYChart.Data(st.getKey(), st.getValue()));
    }
    lineChart.getData().addAll(series);
    dialog.getDialogPane().setContent(lineChart);
    dialog.setResizable(true);
    dialog.showAndWait();
}
 
Example 11
Project: Virtual-Trading   File: Chart.java   View source code 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
protected void makeChart(String comp, String period, String periodCB, String interval) {
  XYChart.Series series = new XYChart.Series();
  List<ChartData> stocks = getChartData(comp, period, periodCB, interval);
  for (int i = stocks.size() - 1; i >= 0; i--) {
    findStartAndEnd(stocks, i);
    XYChart.Data data = setData(stocks, i);
    series.getData().add(data);
  }
  final NumberAxis yAxis =
      new NumberAxis(startValue, endValue * 1.04, (endValue - startValue) / 20);
  final CategoryAxis xAxis = new CategoryAxis();
  lineChart = new LineChart<String, Number>(xAxis, yAxis);
  lineChart.setTitle(comp);
  lineChart.getData().addAll(series);
  lineChart.setLegendVisible(false);
}
 
Example 12
Project: tablesaw   File: FxBar.java   View source code 6 votes vote down vote up
public static BarChart<String, Number> chart(String title, CategoryColumn categoryColumn, NumericColumn
        numericColumn) {

    final CategoryAxis categoryAxis = getCategoryAxis(categoryColumn);
    final NumberAxis numberAxis = getNumberAxis(numericColumn);

    final BarChart<String, Number> barChart = getBarChart(title, categoryAxis, numberAxis);
    List<XYChart.Data<String, Number>> data = new ArrayList<>(categoryColumn.size());

    for (int i = 0; i < categoryColumn.size(); i++) {
        data.add(new XYChart.Data<>(categoryColumn.get(i), numericColumn.getFloat(i)));
    }

    barChart.getData().add(getSeries(numericColumn, data));
    return barChart;
}
 
Example 13
Project: tablesaw   File: FxBar.java   View source code 6 votes vote down vote up
public static BarChart<String, Number> chart(String title, ShortColumn categoryColumn, NumericColumn
        numericColumn) {

    final CategoryAxis categoryAxis = getCategoryAxis(categoryColumn);
    final NumberAxis numberAxis = getNumberAxis(numericColumn);

    final BarChart<String, Number> barChart = getBarChart(title, categoryAxis, numberAxis);
    List<XYChart.Data<String, Number>> data = new ArrayList<>(categoryColumn.size());

    for (int i = 0; i < categoryColumn.size(); i++) {
        data.add(new XYChart.Data<>(categoryColumn.getString(i), numericColumn.getFloat(i)));
    }

    barChart.getData().add(getSeries(numericColumn, data));
    return barChart;
}
 
Example 14
Project: tablesaw   File: FxHorizontalBar.java   View source code 6 votes vote down vote up
public static BarChart<Number, String> chart(String title, CategoryColumn categoryColumn, NumericColumn
        numericColumn) {

    final CategoryAxis categoryAxis = getCategoryAxis(categoryColumn);
    final NumberAxis numberAxis = getNumberAxis(numericColumn);

    final BarChart<Number, String> bar = getNumberStringBarChart(title, numberAxis, categoryAxis);
    List<XYChart.Data<Number, String>> d2 = new ArrayList<>(numericColumn.size());

    for (int i = 0; i < numericColumn.size(); i++) {
        d2.add(new XYChart.Data<>(numericColumn.getFloat(i), categoryColumn.get(i)));
    }

    XYChart.Series<Number, String> series1 = getNumberStringSeries(categoryColumn, d2);

    bar.getData().add(series1);
    return bar;
}
 
Example 15
Project: tablesaw   File: FxHorizontalBar.java   View source code 6 votes vote down vote up
public static BarChart<Number, String> chart(String title, ShortColumn categoryColumn, NumericColumn
        numericColumn) {

    final CategoryAxis categoryAxis = getCategoryAxis(categoryColumn);
    final NumberAxis numberAxis = getNumberAxis(numericColumn);

    final BarChart<Number, String> bar = getNumberStringBarChart(title, numberAxis, categoryAxis);
    List<XYChart.Data<Number, String>> d2 = new ArrayList<>(numericColumn.size());

    for (int i = 0; i < numericColumn.size(); i++) {
        d2.add(new XYChart.Data<>(numericColumn.getFloat(i), categoryColumn.getString(i)));
    }

    XYChart.Series<Number, String> series1 = getNumberStringSeries(categoryColumn, d2);

    bar.getData().add(series1);
    return bar;
}
 
Example 16
Project: tablesaw   File: FxHorizontalBar.java   View source code 6 votes vote down vote up
public static BarChart<Number, String> chart(String title, IntColumn categoryColumn, NumericColumn numericColumn) {

        final CategoryAxis categoryAxis = getCategoryAxis(categoryColumn);
        final NumberAxis numberAxis = getNumberAxis(numericColumn);

        final BarChart<Number, String> bar = getNumberStringBarChart(title, numberAxis, categoryAxis);
        List<XYChart.Data<Number, String>> d2 = new ArrayList<>(numericColumn.size());

        for (int i = 0; i < numericColumn.size(); i++) {
            d2.add(new XYChart.Data<>(numericColumn.getFloat(i), categoryColumn.getString(i)));
        }

        XYChart.Series<Number, String> series1 = getNumberStringSeries(categoryColumn, d2);

        bar.getData().add(series1);
        return bar;
    }
 
Example 17
Project: tablesaw   File: FxPareto.java   View source code 6 votes vote down vote up
public static BarChart<String, Number> chart(String title, IntColumn categoryColumn, NumericColumn numericColumn) {

        Table t = Table.create("", categoryColumn, numericColumn);
        t = t.sortDescendingOn(numericColumn.name());

        final CategoryAxis categoryAxis = getCategoryAxis(t.categoryColumn(0));
        final NumberAxis numberAxis = getNumberAxis(t.numericColumn(1));

        final BarChart<String, Number> barChart = getBarChart(title, categoryAxis, numberAxis);
        List<XYChart.Data<String, Number>> data = new ArrayList<>(categoryColumn.size());

        for (int i = 0; i < categoryColumn.size(); i++) {
            data.add(new XYChart.Data<>(categoryColumn.getString(i), numericColumn.getFloat(i)));
        }

        barChart.getData().add(getSeries(numericColumn, data));
        return barChart;
    }
 
Example 18
Project: tablesaw   File: FxPareto.java   View source code 6 votes vote down vote up
public static BarChart<String, Number> chart(String title, ShortColumn categoryColumn, NumericColumn
        numericColumn) {

    Table t = Table.create("", categoryColumn, numericColumn);
    t = t.sortDescendingOn(numericColumn.name());

    final CategoryAxis categoryAxis = getCategoryAxis(t.categoryColumn(0));
    final NumberAxis numberAxis = getNumberAxis(t.numericColumn(1));

    final BarChart<String, Number> barChart = getBarChart(title, categoryAxis, numberAxis);
    List<XYChart.Data<String, Number>> data = new ArrayList<>(categoryColumn.size());

    for (int i = 0; i < categoryColumn.size(); i++) {
        data.add(new XYChart.Data<>(categoryColumn.getString(i), numericColumn.getFloat(i)));
    }

    barChart.getData().add(getSeries(numericColumn, data));
    return barChart;
}
 
Example 19
Project: polTool   File: GraphView.java   View source code 6 votes vote down vote up
public GraphView(GraphModel model, Stage primaryStage) {

		Stage stage = new Stage();
		stage.initModality(Modality.NONE);
		stage.initOwner(primaryStage);

		stage.setTitle(model.getStageTitle());
		CategoryAxis xAxis = model.getXAxis();
		NumberAxis yAxis = model.getYAxis();
		StackedBarChart<String, Number> bc = new StackedBarChart<String, Number>(
				xAxis, yAxis);
		bc.setTitle(model.getBarTitle());

		Scene scene = new Scene(bc, 800, 600);
		bc.getData().addAll(model.getSeries());
		stage.setScene(scene);
		stage.show();
	}
 
Example 20
Project: Map-Projections   File: MapAnalyzer.java   View source code 6 votes vote down vote up
private Region buildDistortionHistograms() {
	this.sizeChart = new BarChart<String, Number>(new CategoryAxis(), new NumberAxis());
	this.sizeChart.setPrefWidth(CHART_WIDTH);
	this.sizeChart.setPrefHeight(IMG_WIDTH/2);
	this.sizeChart.getXAxis().setLabel("Scale factor");
	this.sizeChart.setBarGap(0);
	this.sizeChart.setCategoryGap(0);
	this.sizeChart.setAnimated(false);
	this.sizeChart.setLegendVisible(false);
	
	this.shapeChart = new BarChart<String, Number>(new CategoryAxis(), new NumberAxis());
	this.shapeChart.setPrefWidth(CHART_WIDTH);
	this.shapeChart.setPrefHeight(IMG_WIDTH/2);
	this.shapeChart.getXAxis().setLabel("Stretch factor");
	this.shapeChart.setBarGap(0);
	this.shapeChart.setCategoryGap(0);
	this.shapeChart.setAnimated(false);
	this.shapeChart.setLegendVisible(false);
	
	return new VBox(5, sizeChart, shapeChart);
}
 
Example 21
Project: mcanalytics   File: ChartPane.java   View source code 6 votes vote down vote up
private void handleFirstLoginsChart() throws IOException, InterruptedException, ExecutionException {
    FutureRequest<LinkedHashMap<LocalDateTime, Integer>> requestResult = sock.submit(new NewPlayerLoginsRequest(
            startDatePicker.getValue(),
            endDatePicker.getValue().plusDays(1)
    ));

    LinkedHashMap<LocalDateTime, Integer> counts = requestResult.get();
    XYChart.Series<String, Number> series = new XYChart.Series<>();
    for(Map.Entry<LocalDateTime, Integer> e : counts.entrySet()) {
        series.getData().add(new XYChart.Data(e.getKey().toString(), e.getValue()));
    }
    series.setName("New Players");
    final CategoryAxis xAxis = new CategoryAxis();
    final NumberAxis yAxis = new NumberAxis();
    xAxis.setLabel("Time Joined");
    yAxis.setLabel("Players Joined");
    yAxis.setTickLength(5);
    yAxis.setMinorTickLength(1);
    xAxis.setAutoRanging(true);
    final BarChart<String, Number> barChart = new BarChart<>(xAxis, yAxis);
    barChart.setTitle("New Players");
    barChart.getData().add(series);

    chartPane.setCenter(barChart);
    chartPane.layout();
}
 
Example 22
Project: tablesaw   File: FxBar.java   View source code 6 votes vote down vote up
public static BarChart<String, Number> chart(String title, CategoryColumn categoryColumn, NumericColumn
        numericColumn) {

    final CategoryAxis categoryAxis = getCategoryAxis(categoryColumn);
    final NumberAxis numberAxis = getNumberAxis(numericColumn);

    final BarChart<String, Number> barChart = getBarChart(title, categoryAxis, numberAxis);
    List<XYChart.Data<String, Number>> data = new ArrayList<>(categoryColumn.size());

    for (int i = 0; i < categoryColumn.size(); i++) {
        data.add(new XYChart.Data<>(categoryColumn.get(i), numericColumn.getFloat(i)));
    }

    barChart.getData().add(getSeries(numericColumn, data));
    return barChart;
}
 
Example 23
Project: tablesaw   File: FxBar.java   View source code 6 votes vote down vote up
public static BarChart<String, Number> chart(String title, ShortColumn categoryColumn, NumericColumn
        numericColumn) {

    final CategoryAxis categoryAxis = getCategoryAxis(categoryColumn);
    final NumberAxis numberAxis = getNumberAxis(numericColumn);

    final BarChart<String, Number> barChart = getBarChart(title, categoryAxis, numberAxis);
    List<XYChart.Data<String, Number>> data = new ArrayList<>(categoryColumn.size());

    for (int i = 0; i < categoryColumn.size(); i++) {
        data.add(new XYChart.Data<>(categoryColumn.getString(i), numericColumn.getFloat(i)));
    }

    barChart.getData().add(getSeries(numericColumn, data));
    return barChart;
}
 
Example 24
Project: tablesaw   File: FxHorizontalBar.java   View source code 6 votes vote down vote up
public static BarChart<Number, String> chart(String title, CategoryColumn categoryColumn, NumericColumn
        numericColumn) {

    final CategoryAxis categoryAxis = getCategoryAxis(categoryColumn);
    final NumberAxis numberAxis = getNumberAxis(numericColumn);

    final BarChart<Number, String> bar = getNumberStringBarChart(title, numberAxis, categoryAxis);
    List<XYChart.Data<Number, String>> d2 = new ArrayList<>(numericColumn.size());

    for (int i = 0; i < numericColumn.size(); i++) {
        d2.add(new XYChart.Data<>(numericColumn.getFloat(i), categoryColumn.get(i)));
    }

    XYChart.Series<Number, String> series1 = getNumberStringSeries(categoryColumn, d2);

    bar.getData().add(series1);
    return bar;
}
 
Example 25
Project: tablesaw   File: FxHorizontalBar.java   View source code 6 votes vote down vote up
public static BarChart<Number, String> chart(String title, ShortColumn categoryColumn, NumericColumn
        numericColumn) {

    final CategoryAxis categoryAxis = getCategoryAxis(categoryColumn);
    final NumberAxis numberAxis = getNumberAxis(numericColumn);

    final BarChart<Number, String> bar = getNumberStringBarChart(title, numberAxis, categoryAxis);
    List<XYChart.Data<Number, String>> d2 = new ArrayList<>(numericColumn.size());

    for (int i = 0; i < numericColumn.size(); i++) {
        d2.add(new XYChart.Data<>(numericColumn.getFloat(i), categoryColumn.getString(i)));
    }

    XYChart.Series<Number, String> series1 = getNumberStringSeries(categoryColumn, d2);

    bar.getData().add(series1);
    return bar;
}
 
Example 26
Project: tablesaw   File: FxHorizontalBar.java   View source code 6 votes vote down vote up
public static BarChart<Number, String> chart(String title, IntColumn categoryColumn, NumericColumn numericColumn) {

        final CategoryAxis categoryAxis = getCategoryAxis(categoryColumn);
        final NumberAxis numberAxis = getNumberAxis(numericColumn);

        final BarChart<Number, String> bar = getNumberStringBarChart(title, numberAxis, categoryAxis);
        List<XYChart.Data<Number, String>> d2 = new ArrayList<>(numericColumn.size());

        for (int i = 0; i < numericColumn.size(); i++) {
            d2.add(new XYChart.Data<>(numericColumn.getFloat(i), categoryColumn.getString(i)));
        }

        XYChart.Series<Number, String> series1 = getNumberStringSeries(categoryColumn, d2);

        bar.getData().add(series1);
        return bar;
    }
 
Example 27
Project: tablesaw   File: FxPareto.java   View source code 6 votes vote down vote up
public static BarChart<String, Number> chart(String title, IntColumn categoryColumn, NumericColumn numericColumn) {

        Table t = Table.create("", categoryColumn, numericColumn);
        t = t.sortDescendingOn(numericColumn.name());

        final CategoryAxis categoryAxis = getCategoryAxis(t.categoryColumn(0));
        final NumberAxis numberAxis = getNumberAxis(t.numericColumn(1));

        final BarChart<String, Number> barChart = getBarChart(title, categoryAxis, numberAxis);
        List<XYChart.Data<String, Number>> data = new ArrayList<>(categoryColumn.size());

        for (int i = 0; i < categoryColumn.size(); i++) {
            data.add(new XYChart.Data<>(categoryColumn.getString(i), numericColumn.getFloat(i)));
        }

        barChart.getData().add(getSeries(numericColumn, data));
        return barChart;
    }
 
Example 28
Project: tablesaw   File: FxPareto.java   View source code 6 votes vote down vote up
public static BarChart<String, Number> chart(String title, ShortColumn categoryColumn, NumericColumn
        numericColumn) {

    Table t = Table.create("", categoryColumn, numericColumn);
    t = t.sortDescendingOn(numericColumn.name());

    final CategoryAxis categoryAxis = getCategoryAxis(t.categoryColumn(0));
    final NumberAxis numberAxis = getNumberAxis(t.numericColumn(1));

    final BarChart<String, Number> barChart = getBarChart(title, categoryAxis, numberAxis);
    List<XYChart.Data<String, Number>> data = new ArrayList<>(categoryColumn.size());

    for (int i = 0; i < categoryColumn.size(); i++) {
        data.add(new XYChart.Data<>(categoryColumn.getString(i), numericColumn.getFloat(i)));
    }

    barChart.getData().add(getSeries(numericColumn, data));
    return barChart;
}
 
Example 29
Project: kotlinfx-ensemble   File: AdvLineCategoryChartSample.java   View source code 6 votes vote down vote up
protected LineChart<String, Number> createChart() {
    final CategoryAxis xAxis = new CategoryAxis();
    final NumberAxis yAxis = new NumberAxis();
    final LineChart<String,Number> lc = new LineChart<String,Number>(xAxis,yAxis);
    // setup chart
    lc.setTitle("LineChart with Category Axis");
    xAxis.setLabel("X Axis");
    yAxis.setLabel("Y Axis");
    // add starting data
    XYChart.Series<String,Number> series = new XYChart.Series<String,Number>();
    series.setName("Data Series 1");
    series.getData().add(new XYChart.Data<String,Number>(CATEGORIES[0], 50d));
    series.getData().add(new XYChart.Data<String,Number>(CATEGORIES[1], 80d));
    series.getData().add(new XYChart.Data<String,Number>(CATEGORIES[2], 90d));
    series.getData().add(new XYChart.Data<String,Number>(CATEGORIES[3], 30d));
    series.getData().add(new XYChart.Data<String,Number>(CATEGORIES[4], 122d));
    series.getData().add(new XYChart.Data<String,Number>(CATEGORIES[5], 10d));
    lc.getData().add(series);
    return lc;
}
 
Example 30
Project: kotlinfx-ensemble   File: BarChartSample.java   View source code 6 votes vote down vote up
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);
}
 
Example 31
Project: kotlinfx-ensemble   File: ImageBarChartSample.java   View source code 6 votes vote down vote up
public ImageBarChartSample() {

        String imageBarChartCss = ImageBarChartSample.class.getResource("ImageBarChart.css").toExternalForm();

        BarChart barChart = new BarChart(new CategoryAxis(), new NumberAxis());
        barChart.setLegendVisible(false);
        barChart.getStylesheets().add(imageBarChartCss);

        barChart.getData().add(
                new XYChart.Series<String, Integer>("Sales Per Product",
                FXCollections.observableArrayList(
                new XYChart.Data<String, Integer>("SUV", 120),
                new XYChart.Data<String, Integer>("Sedan", 50),
                new XYChart.Data<String, Integer>("Truck", 180),
                new XYChart.Data<String, Integer>("Van", 20))));

        Scene scene = new Scene(barChart, 350, 300);
        scene.getStylesheets().add(ImageBarChartSample.class.getResource("ImageBarChart.css").toString());
        getChildren().add(barChart);
    }
 
Example 32
Project: incubator-netbeans   File: SwingInterop.java   View source code 5 votes vote down vote up
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;
}
 
Example 33
Project: incubator-netbeans   File: ChartAdvancedBar.java   View source code 5 votes vote down vote up
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;
}
 
Example 34
Project: incubator-netbeans   File: ChartAudioBar.java   View source code 5 votes vote down vote up
protected BarChart<String, Number> createChart() {
    final CategoryAxis xAxis = new CategoryAxis();
    final NumberAxis yAxis = new NumberAxis(0,50,10);
    final BarChart<String,Number> bc = new BarChart<String,Number>(xAxis,yAxis);
    bc.setId("barAudioDemo");
    bc.setLegendVisible(false);
    bc.setAnimated(false);
    bc.setBarGap(0);
    bc.setCategoryGap(1);
    bc.setVerticalGridLinesVisible(false);
    // setup chart
    bc.setTitle("Live Audio Spectrum Data");
    xAxis.setLabel("Frequency Bands");
    yAxis.setLabel("Magnitudes");
    yAxis.setTickLabelFormatter(new NumberAxis.DefaultFormatter(yAxis,null,"dB"));
    // add starting data
    XYChart.Series<String,Number> series1 = new XYChart.Series<String,Number>();
    series1.setName("Data Series 1");
    //noinspection unchecked
    series1Data = new XYChart.Data[128];
    String[] categories = new String[128];
    for (int i=0; i<series1Data.length; i++) {
        categories[i] = Integer.toString(i+1);
        series1Data[i] = new XYChart.Data<String,Number>(categories[i],50);
        series1.getData().add(series1Data[i]);
    }
    bc.getData().add(series1);
    return bc;
}
 
Example 35
Project: marathonv5   File: AdvHorizontalBarChartSample.java   View source code 5 votes vote down vote up
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;
}
 
Example 36
Project: marathonv5   File: AdvancedBarChartSample.java   View source code 5 votes vote down vote up
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;
}
 
Example 37
Project: marathonv5   File: AdvBarAudioChartSample.java   View source code 5 votes vote down vote up
protected BarChart<String, Number> createChart() {
    final CategoryAxis xAxis = new CategoryAxis();
    final NumberAxis yAxis = new NumberAxis(0,50,10);
    final BarChart<String,Number> bc = new BarChart<String,Number>(xAxis,yAxis);
    bc.setId("barAudioDemo");
    bc.setLegendVisible(false);
    bc.setAnimated(false);
    bc.setBarGap(0);
    bc.setCategoryGap(1);
    bc.setVerticalGridLinesVisible(false);
    // setup chart
    bc.setTitle("Live Audio Spectrum Data");
    xAxis.setLabel("Frequency Bands");
    yAxis.setLabel("Magnitudes");
    yAxis.setTickLabelFormatter(new NumberAxis.DefaultFormatter(yAxis,null,"dB"));
    // add starting data
    XYChart.Series<String,Number> series1 = new XYChart.Series<String,Number>();
    series1.setName("Data Series 1");
    //noinspection unchecked
    series1Data = new XYChart.Data[128];
    String[] categories = new String[128];
    for (int i=0; i<series1Data.length; i++) {
        categories[i] = Integer.toString(i+1);
        series1Data[i] = new XYChart.Data<String,Number>(categories[i],50);
        series1.getData().add(series1Data[i]);
    }
    bc.getData().add(series1);
    return bc;
}
 
Example 38
Project: marathonv5   File: SwingInterop.java   View source code 5 votes vote down vote up
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;
}
 
Example 39
Project: marathonv5   File: AdvHorizontalBarChartSample.java   View source code 5 votes vote down vote up
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;
}
 
Example 40
Project: marathonv5   File: AdvancedBarChartSample.java   View source code 5 votes vote down vote up
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;
}