javafx.scene.chart.ScatterChart Java Examples

The following examples show how to use javafx.scene.chart.ScatterChart. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ScatterChartSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public ScatterChartSample() {
    NumberAxis xAxis = new NumberAxis("X-Axis", 0d, 8.0d, 1.0d);
    NumberAxis yAxis = new NumberAxis("Y-Axis", 0.0d, 5.0d, 1.0d);
    ObservableList<XYChart.Series> data = FXCollections.observableArrayList(
        new ScatterChart.Series("Series 1", FXCollections.<ScatterChart.Data>observableArrayList(
            new XYChart.Data(0.2, 3.5),
            new XYChart.Data(0.7, 4.6),
            new XYChart.Data(1.8, 1.7),
            new XYChart.Data(2.1, 2.8),
            new XYChart.Data(4.0, 2.2),
            new XYChart.Data(4.1, 2.6),
            new XYChart.Data(4.5, 2.0),
            new XYChart.Data(6.0, 3.0),
            new XYChart.Data(7.0, 2.0),
            new XYChart.Data(7.8, 4.0)
        ))
    );
    ScatterChart chart = new ScatterChart(xAxis, yAxis, data);
    getChildren().add(chart);
}
 
Example #2
Source File: AdvScatterLiveChartSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
protected ScatterChart<Number, Number> createChart() {
    final NumberAxis xAxis = new NumberAxis();
    xAxis.setForceZeroInRange(false);
    final NumberAxis yAxis = new NumberAxis(-100,100,10);
    final ScatterChart<Number,Number> sc = new ScatterChart<Number,Number>(xAxis,yAxis);
    // setup chart
    sc.setId("liveScatterChart");
    sc.setTitle("Animated Sine Wave ScatterChart");
    xAxis.setLabel("X Axis");
    xAxis.setAnimated(false);
    yAxis.setLabel("Y Axis");
    yAxis.setAutoRanging(false);
    // add starting data
    series = new ScatterChart.Series<Number,Number>();
    series.setName("Sine Wave");
    series.getData().add(new ScatterChart.Data<Number, Number>(5d, 5d));
    sc.getData().add(series);
    return sc;
}
 
Example #3
Source File: AdvancedScatterChartSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
protected ScatterChart<Number, Number> createChart() {
    final NumberAxis xAxis = new NumberAxis();
    xAxis.setSide(Side.TOP);
    final NumberAxis yAxis = new NumberAxis();
    yAxis.setSide(Side.RIGHT);
    final ScatterChart<Number,Number> sc = new ScatterChart<Number,Number>(xAxis,yAxis);
    // setup chart
    xAxis.setLabel("X Axis");
    yAxis.setLabel("Y Axis");
    // add starting data
    for (int s=0;s<5;s++) {
        XYChart.Series<Number, Number> series = new XYChart.Series<Number, Number>();
        series.setName("Data Series "+s);
        for (int i=0; i<30; i++) series.getData().add(new XYChart.Data<Number, Number>(Math.random()*98, Math.random()*98));
        sc.getData().add(series);
    }
    return sc;
}
 
Example #4
Source File: ScatterChartSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public ScatterChartSample() {
    NumberAxis xAxis = new NumberAxis("X-Axis", 0d, 8.0d, 1.0d);
    NumberAxis yAxis = new NumberAxis("Y-Axis", 0.0d, 5.0d, 1.0d);
    ObservableList<XYChart.Series> data = FXCollections.observableArrayList(
        new ScatterChart.Series("Series 1", FXCollections.<ScatterChart.Data>observableArrayList(
            new XYChart.Data(0.2, 3.5),
            new XYChart.Data(0.7, 4.6),
            new XYChart.Data(1.8, 1.7),
            new XYChart.Data(2.1, 2.8),
            new XYChart.Data(4.0, 2.2),
            new XYChart.Data(4.1, 2.6),
            new XYChart.Data(4.5, 2.0),
            new XYChart.Data(6.0, 3.0),
            new XYChart.Data(7.0, 2.0),
            new XYChart.Data(7.8, 4.0)
        ))
    );
    ScatterChart chart = new ScatterChart(xAxis, yAxis, data);
    getChildren().add(chart);
}
 
Example #5
Source File: AdvScatterLiveChartSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
protected ScatterChart<Number, Number> createChart() {
    final NumberAxis xAxis = new NumberAxis();
    xAxis.setForceZeroInRange(false);
    final NumberAxis yAxis = new NumberAxis(-100,100,10);
    final ScatterChart<Number,Number> sc = new ScatterChart<Number,Number>(xAxis,yAxis);
    // setup chart
    sc.setId("liveScatterChart");
    sc.setTitle("Animated Sine Wave ScatterChart");
    xAxis.setLabel("X Axis");
    xAxis.setAnimated(false);
    yAxis.setLabel("Y Axis");
    yAxis.setAutoRanging(false);
    // add starting data
    series = new ScatterChart.Series<Number,Number>();
    series.setName("Sine Wave");
    series.getData().add(new ScatterChart.Data<Number, Number>(5d, 5d));
    sc.getData().add(series);
    return sc;
}
 
Example #6
Source File: AdvancedScatterChartSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
protected ScatterChart<Number, Number> createChart() {
    final NumberAxis xAxis = new NumberAxis();
    xAxis.setSide(Side.TOP);
    final NumberAxis yAxis = new NumberAxis();
    yAxis.setSide(Side.RIGHT);
    final ScatterChart<Number,Number> sc = new ScatterChart<Number,Number>(xAxis,yAxis);
    // setup chart
    xAxis.setLabel("X Axis");
    yAxis.setLabel("Y Axis");
    // add starting data
    for (int s=0;s<5;s++) {
        XYChart.Series<Number, Number> series = new XYChart.Series<Number, Number>();
        series.setName("Data Series "+s);
        for (int i=0; i<30; i++) series.getData().add(new XYChart.Data<Number, Number>(Math.random()*98, Math.random()*98));
        sc.getData().add(series);
    }
    return sc;
}
 
Example #7
Source File: ChartAdvancedScatter.java    From netbeans with Apache License 2.0 6 votes vote down vote up
protected ScatterChart<Number, Number> createChart() {
    final NumberAxis xAxis = new NumberAxis();
    xAxis.setSide(Side.TOP);
    final NumberAxis yAxis = new NumberAxis();
    yAxis.setSide(Side.RIGHT);
    final ScatterChart<Number,Number> sc = new ScatterChart<Number,Number>(xAxis,yAxis);
    // setup chart
    xAxis.setLabel("X Axis");
    yAxis.setLabel("Y Axis");
    // add starting data
    for (int s=0;s<5;s++) {
        XYChart.Series<Number, Number> series = new XYChart.Series<Number, Number>();
        series.setName("Data Series "+s);
        for (int i=0; i<30; i++) series.getData().add(new XYChart.Data<Number, Number>(Math.random()*98, Math.random()*98));
        sc.getData().add(series);
    }
    return sc;
}
 
Example #8
Source File: ChartAdvancedScatterLive.java    From netbeans with Apache License 2.0 6 votes vote down vote up
protected ScatterChart<Number, Number> createChart() {
    final NumberAxis xAxis = new NumberAxis();
    xAxis.setForceZeroInRange(false);
    final NumberAxis yAxis = new NumberAxis(-100,100,10);
    final ScatterChart<Number,Number> sc = new ScatterChart<Number,Number>(xAxis,yAxis);
    // setup chart
    sc.setId("liveScatterChart");
    sc.setTitle("Animated Sine Wave ScatterChart");
    xAxis.setLabel("X Axis");
    xAxis.setAnimated(false);
    yAxis.setLabel("Y Axis");
    yAxis.setAutoRanging(false);
    // add starting data
    series = new ScatterChart.Series<Number,Number>();
    series.setName("Sine Wave");
    series.getData().add(new ScatterChart.Data<Number, Number>(5d, 5d));
    sc.getData().add(series);
    return sc;
}
 
Example #9
Source File: ScatterChart - MainApp.java    From Java-for-Data-Science with MIT License 5 votes vote down vote up
@Override
public void start(Stage stage) throws Exception {
    stage.setTitle("Scatter Chart Sample");
    final NumberAxis yAxis = new NumberAxis(1400, 2100, 100);
    final NumberAxis xAxis = new NumberAxis(500000, 90000000, 1000000);
    final ScatterChart<Number, Number> scatterChart = new ScatterChart<>(xAxis, yAxis);
    xAxis.setLabel("Population");
    yAxis.setLabel("Decade");
    scatterChart.setTitle("Population Scatter Graph");

    XYChart.Series series = new XYChart.Series();

    try (CSVReader dataReader = new CSVReader(new FileReader("EuropeanScatterData.csv"), ',')) {
        String[] nextLine;
        while ((nextLine = dataReader.readNext()) != null) {
            int decade = Integer.parseInt(nextLine[0]);
            int population = Integer.parseInt(nextLine[1]);
            series.getData().add(new XYChart.Data(population, decade));
            System.out.println("Decade: " + decade + "  Population: " + population);
        }
    }

    scatterChart.getData().addAll(series);
    Scene scene = new Scene(scatterChart, 500, 400);
    stage.setScene(scene);
    stage.show();
}
 
Example #10
Source File: Clustering.java    From java-ml-projects with Apache License 2.0 5 votes vote down vote up
private ScatterChart<Number, Number> buildChart(String chartName, List<XYChart.Series<Number, Number>> series) {
	final NumberAxis xAxis = new NumberAxis();
	final NumberAxis yAxis = new NumberAxis();
	final ScatterChart<Number, Number> sc = new ScatterChart<Number, Number>(xAxis, yAxis);
	sc.setTitle(chartName);
	sc.setPrefHeight(450);
	sc.setPrefWidth(600);
	xAxis.getValueForDisplay(1);
	yAxis.getValueForDisplay(2);
	sc.getData().addAll(series);
	return sc;
}
 
Example #11
Source File: ScatterChartBuilderService.java    From AsciidocFX with Apache License 2.0 5 votes vote down vote up
@Override
protected XYChart<String, Number> createXYChart() {
    final CategoryAxis xAxis = new CategoryAxis();
    final NumberAxis yAxis = new NumberAxis();
    final XYChart<String, Number> chart = new ScatterChart<String, Number>(xAxis, yAxis);
    chart.getStyleClass().add("chart-extension");
    return chart;
}
 
Example #12
Source File: ChartBuilder.java    From constellation with Apache License 2.0 4 votes vote down vote up
public ScatterChart<X, Y> build(GraphReadMethods graph, ScatterPlotState state, Set<ScatterData> currentData, Set<ScatterData> currentSelectedData) {
    currentData.clear();
    currentSelectedData.clear();

    XYChart.Series<X, Y> series = new XYChart.Series<>();
    series.setName(state.getXAttribute() + " vs. " + state.getYAttribute());

    final int selectedAttribute = graph.getAttribute(state.getElementType(), VisualConcept.VertexAttribute.SELECTED.getName());
    final int labelAttribute = graph.getAttribute(state.getElementType(), VisualConcept.VertexAttribute.LABEL.getName());

    final int elementCount = state.getElementType().getElementCount(graph);
    for (int elementPosition = 0; elementPosition < elementCount; elementPosition++) {
        final int elementId = state.getElementType().getElement(graph, elementPosition);
        if (!state.isSelectedOnly() || graph.getBooleanValue(selectedAttribute, elementId)) {
            final String elementLabel = graph.getStringValue(labelAttribute, elementId);
            final X vertexXValue = xAxisBuilder.getValue(graph, state.getElementType(), state.getXAttribute().getId(), elementId);
            final Y vertexYValue = yAxisBuilder.getValue(graph, state.getElementType(), state.getYAttribute().getId(), elementId);
            final XYChart.Data<X, Y> data = new XYChart.Data<>(vertexXValue, vertexYValue);
            final ScatterData scatterData = new ScatterData(elementId, elementLabel, data);
            currentData.add(scatterData);
            if (graph.getBooleanValue(selectedAttribute, elementId)) {
                currentSelectedData.add(scatterData);
            }
            series.getData().add(data);
        }
    }

    final Axis<X> xAxis = xAxisBuilder.build();
    xAxis.setLabel(state.getXAttribute().getName());

    final Axis<Y> yAxis = yAxisBuilder.build();
    yAxis.setLabel(state.getYAttribute().getName());

    final ScatterChart<X, Y> scatterChart = new ScatterChart<>(xAxis, yAxis);
    scatterChart.setLegendVisible(false);
    scatterChart.setHorizontalGridLinesVisible(false);
    scatterChart.setVerticalGridLinesVisible(false);

    scatterChart.getData().clear();
    scatterChart.getData().add(series);

    return scatterChart;
}
 
Example #13
Source File: MainApp-Camping.java    From Java-for-Data-Science with MIT License 4 votes vote down vote up
@Override
    public void start(Stage stage) throws Exception {
        stage.setTitle("Scatter Chart Sample");
        final NumberAxis xAxis = new NumberAxis(0, 100, 10);
        final NumberAxis yAxis = new NumberAxis(0, 130000, 10000);        
        final ScatterChart<Number,Number> sc = new
            ScatterChart<Number,Number>(xAxis,yAxis);
        xAxis.setLabel("Age");                
        yAxis.setLabel("Income");
        sc.setTitle("Camping Inclination");
       
        /*
23,45600,1
26,32000,0
45,65700,1
29,25300,0
72,55600,1
24,28700,1
56,125300,1
22,34200,1
28,32800,1
32,24600,1
25,36500,1
67,76800,0
25,14500,1
86,58900,0
        */
        XYChart.Series series1 = new XYChart.Series();
        series1.setName("Camps");
        series1.getData().add(new XYChart.Data(23,45600));
        series1.getData().add(new XYChart.Data(45,65700));
        series1.getData().add(new XYChart.Data(72,55600));
        series1.getData().add(new XYChart.Data(24,28700));
        series1.getData().add(new XYChart.Data(22,34200));
        series1.getData().add(new XYChart.Data(28,32800));
        series1.getData().add(new XYChart.Data(32,24600));
        series1.getData().add(new XYChart.Data(25,36500));
        series1.getData().add(new XYChart.Data(22,43600));
        series1.getData().add(new XYChart.Data(78,125700));
        series1.getData().add(new XYChart.Data(73,56500));
        
        XYChart.Series series2 = new XYChart.Series();
        series2.setName("Doesn't Camp");
        series2.getData().add(new XYChart.Data(26,91000));
        series2.getData().add(new XYChart.Data(29,85300));
        series2.getData().add(new XYChart.Data(67,76800));
        series2.getData().add(new XYChart.Data(86,58900));
        series2.getData().add(new XYChart.Data(56,125300));
        series2.getData().add(new XYChart.Data(25,125000));
        series2.getData().add(new XYChart.Data(29,87600));
        series2.getData().add(new XYChart.Data(65,79300));
 
        sc.getData().addAll(series1, series2);
        Scene scene  = new Scene(sc, 500, 400);
        stage.setScene(scene);
        stage.show();
    }