Java Code Examples for javafx.scene.chart.XYChart

The following are top voted examples for showing how to use javafx.scene.chart.XYChart. 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: incubator-netbeans   File: ChartLine.java   View source code 9 votes vote down vote up
private void init(Stage primaryStage) {
    Group root = new Group();
    primaryStage.setScene(new Scene(root));
    NumberAxis xAxis = new NumberAxis("Values for X-Axis", 0, 3, 1);
    NumberAxis yAxis = new NumberAxis("Values for Y-Axis", 0, 3, 1);
    ObservableList<XYChart.Series<Double,Double>> lineChartData = FXCollections.observableArrayList(
        new LineChart.Series<Double,Double>("Series 1", FXCollections.observableArrayList(
            new XYChart.Data<Double,Double>(0.0, 1.0),
            new XYChart.Data<Double,Double>(1.2, 1.4),
            new XYChart.Data<Double,Double>(2.2, 1.9),
            new XYChart.Data<Double,Double>(2.7, 2.3),
            new XYChart.Data<Double,Double>(2.9, 0.5)
        )),
        new LineChart.Series<Double,Double>("Series 2", FXCollections.observableArrayList(
            new XYChart.Data<Double,Double>(0.0, 1.6),
            new XYChart.Data<Double,Double>(0.8, 0.4),
            new XYChart.Data<Double,Double>(1.4, 2.9),
            new XYChart.Data<Double,Double>(2.1, 1.3),
            new XYChart.Data<Double,Double>(2.6, 0.9)
        ))
    );
    LineChart chart = new LineChart(xAxis, yAxis, lineChartData);
    root.getChildren().add(chart);
}
 
Example 2
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 3
Project: marathonv5   File: AdvCandleStickChartSample.java   View source code 7 votes vote down vote up
@Override protected void seriesRemoved(Series<Number, Number> series) {
    // remove all candle nodes
    for (XYChart.Data<Number, Number> d : series.getData()) {
        final Node candle = d.getNode();
        if (shouldAnimate()) {
            // fade out old candle
            FadeTransition ft = new FadeTransition(Duration.millis(500), candle);
            ft.setToValue(0);
            ft.setOnFinished(new EventHandler<ActionEvent>() {

                @Override
                public void handle(ActionEvent actionEvent) {
                    getPlotChildren().remove(candle);
                }
            });
            ft.play();
        } else {
            getPlotChildren().remove(candle);
        }
    }
}
 
Example 4
Project: Money-Manager   File: ExpenseChart.java   View source code 6 votes vote down vote up
public static Series<String, Number> getExpenseData(String monthName) {
	
	XYChart.Series<String, Number> sector = new XYChart.Series<>();
	String allSector[] = new ComboboxList().getSectorList();
	
	//chart data for all other Sectors
	for (String sectorName : allSector) {
		String sectorShortName = getAbbreviateName(sectorName);
		double amount = longToDouble(new Sector().getAmountBySectorFromExpense(monthName, sectorName));
		sector.getData().add(new XYChart.Data<>(sectorShortName, amount));
	}			
	
	//chart data for "Adjusted Balance" Sector
	String srtName = getAbbreviateName("Adjusted Balance");
	double amnt = longToDouble(new Sector().getAmountBySectorFromExpense(monthName, "Adjusted Balance"));
	sector.getData().add(new XYChart.Data<>(srtName, amnt));
			
	return sector;
}
 
Example 5
Project: incubator-netbeans   File: ChartAdvancedScatter.java   View source code 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 6
Project: incubator-netbeans   File: ChartAdvancedArea.java   View source code 6 votes vote down vote up
protected AreaChart<Number, Number> createChart() {
    NumberAxis xAxis = new NumberAxis();
    NumberAxis yAxis = new NumberAxis();
    AreaChart<Number,Number> ac = new AreaChart<Number,Number>(xAxis,yAxis);
    // setup chart
    ac.setTitle("Area Chart Example");
    xAxis.setLabel("X Axis");
    yAxis.setLabel("Y Axis");
    // add starting data
    for (int s=0;s<3;s++) {
        XYChart.Series<Number,Number> series = new XYChart.Series<Number,Number>();
        series.setName("Data Series "+s);
        double x = 0;
        while (x<95) {
            series.getData().add(new XYChart.Data<Number,Number>(x, Math.random()*99));
            x += 5 + (15*Math.random());
        }
        series.getData().add(new XYChart.Data<Number,Number>(99d, Math.random()*99));
        ac.getData().add(series);
    }
    return ac;
}
 
Example 7
Project: incubator-netbeans   File: ChartAudioArea.java   View source code 6 votes vote down vote up
protected AreaChart<Number,Number> createChart() {
    final NumberAxis xAxis = new NumberAxis(0,128,8);
    final NumberAxis yAxis = new NumberAxis(0,50,10);
    final AreaChart<Number,Number> ac = new AreaChart<Number,Number>(xAxis,yAxis);
    // setup chart
    ac.setId("audioAreaDemo");
    ac.setLegendVisible(false);
    ac.setTitle("Live Audio Spectrum Data");
    ac.setAnimated(false);
    xAxis.setLabel("Frequency Bands");
    yAxis.setLabel("Magnitudes");
    yAxis.setTickLabelFormatter(new NumberAxis.DefaultFormatter(yAxis,null,"dB"));
    // add starting data
    XYChart.Series<Number,Number> series = new XYChart.Series<Number,Number>();
    series.setName("Audio Spectrum");
    //noinspection unchecked
    series1Data = new XYChart.Data[(int)xAxis.getUpperBound()];
    for (int i=0; i<series1Data.length; i++) {
        series1Data[i] = new XYChart.Data<Number,Number>(i,50);
        series.getData().add(series1Data[i]);
    }
    ac.getData().add(series);
    return ac;
}
 
Example 8
Project: marathonv5   File: ChartActions.java   View source code 6 votes vote down vote up
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)));
}
 
Example 9
Project: marathonv5   File: AdvancedBubbleChartSample.java   View source code 6 votes vote down vote up
protected BubbleChart<Number, Number> createChart() {
    final NumberAxis xAxis = new NumberAxis();
    final NumberAxis yAxis = new NumberAxis();
    final BubbleChart<Number,Number> bc = new BubbleChart<Number,Number>(xAxis,yAxis);
    // setup chart
    bc.setTitle("Advanced BubbleChart");
    xAxis.setLabel("X Axis");
    yAxis.setLabel("Y Axis");
    // add starting data
    XYChart.Series<Number,Number> series1 = new XYChart.Series<Number,Number>();
    series1.setName("Data Series 1");
    for (int i=0; i<20; i++) series1.getData().add(
            new XYChart.Data<Number,Number>(Math.random()*100, Math.random()*100, (Math.random()*10)));
    XYChart.Series<Number,Number> series2 = new XYChart.Series<Number,Number>();
    series2.setName("Data Series 2");
    for (int i=0; i<20; i++) series2.getData().add(
            new XYChart.Data<Number,Number>(Math.random()*100, Math.random()*100, (Math.random()*10)));
    bc.getData().addAll(series1, series2);
    return bc;
}
 
Example 10
Project: marathonv5   File: AdvancedAreaChartSample.java   View source code 6 votes vote down vote up
protected AreaChart<Number, Number> createChart() {
    NumberAxis xAxis = new NumberAxis();
    NumberAxis yAxis = new NumberAxis();
    AreaChart<Number,Number> ac = new AreaChart<Number,Number>(xAxis,yAxis);
    // setup chart
    ac.setTitle("Area Chart Example");
    xAxis.setLabel("X Axis");
    yAxis.setLabel("Y Axis");
    // add starting data
    for (int s=0;s<3;s++) {
        XYChart.Series<Number,Number> series = new XYChart.Series<Number,Number>();
        series.setName("Data Series "+s);
        double x = 0;
        while (x<95) {
            series.getData().add(new XYChart.Data<Number,Number>(x, Math.random()*99));
            x += 5 + (15*Math.random());
        }
        series.getData().add(new XYChart.Data<Number,Number>(99d, Math.random()*99));
        ac.getData().add(series);
    }
    return ac;
}
 
Example 11
Project: Java-oscilloscope-project   File: ZoomManager.java   View source code 6 votes vote down vote up
static <X, Y> ObservableList<XYChart.Data<X, Y>> deepCopySeriesData(
        final Collection<? extends XYChart.Data<X, Y>> data) {
    final ObservableList<XYChart.Data<X, Y>> result = FXCollections.observableArrayList();
    for (final Data<X, Y> i : data) {
        result.add(new Data<>(i.getXValue(), i.getYValue()));
    }
    return result;
}
 
Example 12
Project: marathonv5   File: ChartActions.java   View source code 6 votes vote down vote up
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)));
}
 
Example 13
Project: marathonv5   File: AdvancedLineChartSample.java   View source code 6 votes vote down vote up
protected LineChart<Number, Number> createChart() {
    final NumberAxis xAxis = new NumberAxis();
    final NumberAxis yAxis = new NumberAxis();
    final LineChart<Number,Number> lc = new LineChart<Number,Number>(xAxis,yAxis);
    // setup chart
    lc.setTitle("Basic LineChart");
    xAxis.setLabel("X Axis");
    yAxis.setLabel("Y Axis");
    // add starting data
    XYChart.Series<Number,Number> series = new XYChart.Series<Number,Number>();
    series.setName("Data Series 1");
    series.getData().add(new XYChart.Data<Number,Number>(20d, 50d));
    series.getData().add(new XYChart.Data<Number,Number>(40d, 80d));
    series.getData().add(new XYChart.Data<Number,Number>(50d, 90d));
    series.getData().add(new XYChart.Data<Number,Number>(70d, 30d));
    series.getData().add(new XYChart.Data<Number,Number>(170d, 122d));
    lc.getData().add(series);
    return lc;
}
 
Example 14
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 15
Project: marathonv5   File: LineChartSample.java   View source code 6 votes vote down vote up
public LineChartSample() {
    NumberAxis xAxis = new NumberAxis("Values for X-Axis", 0, 3, 1);
    NumberAxis yAxis = new NumberAxis("Values for Y-Axis", 0, 3, 1);
    ObservableList<XYChart.Series<Double,Double>> lineChartData = FXCollections.observableArrayList(
        new LineChart.Series<Double,Double>("Series 1", FXCollections.observableArrayList(
            new XYChart.Data<Double,Double>(0.0, 1.0),
            new XYChart.Data<Double,Double>(1.2, 1.4),
            new XYChart.Data<Double,Double>(2.2, 1.9),
            new XYChart.Data<Double,Double>(2.7, 2.3),
            new XYChart.Data<Double,Double>(2.9, 0.5)
        )),
        new LineChart.Series<Double,Double>("Series 2", FXCollections.observableArrayList(
            new XYChart.Data<Double,Double>(0.0, 1.6),
            new XYChart.Data<Double,Double>(0.8, 0.4),
            new XYChart.Data<Double,Double>(1.4, 2.9),
            new XYChart.Data<Double,Double>(2.1, 1.3),
            new XYChart.Data<Double,Double>(2.6, 0.9)
        ))
    );
    LineChart chart = new LineChart(xAxis, yAxis, lineChartData);
    getChildren().add(chart);
}
 
Example 16
Project: marathonv5   File: ScatterChartSample.java   View source code 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 17
Project: marathonv5   File: AdvancedAreaChartSample.java   View source code 6 votes vote down vote up
protected AreaChart<Number, Number> createChart() {
    NumberAxis xAxis = new NumberAxis();
    NumberAxis yAxis = new NumberAxis();
    AreaChart<Number,Number> ac = new AreaChart<Number,Number>(xAxis,yAxis);
    // setup chart
    ac.setTitle("Area Chart Example");
    xAxis.setLabel("X Axis");
    yAxis.setLabel("Y Axis");
    // add starting data
    for (int s=0;s<3;s++) {
        XYChart.Series<Number,Number> series = new XYChart.Series<Number,Number>();
        series.setName("Data Series "+s);
        double x = 0;
        while (x<95) {
            series.getData().add(new XYChart.Data<Number,Number>(x, Math.random()*99));
            x += 5 + (15*Math.random());
        }
        series.getData().add(new XYChart.Data<Number,Number>(99d, Math.random()*99));
        ac.getData().add(series);
    }
    return ac;
}
 
Example 18
Project: marathonv5   File: CurveFittedAreaChartSample.java   View source code 6 votes vote down vote up
public CurveFittedAreaChartSample() {
    CurveFittedAreaChart chart = new CurveFittedAreaChart(
            new NumberAxis(0, 10000, 2500), new NumberAxis(0, 1000, 200));
    chart.setLegendVisible(false);
    chart.setHorizontalGridLinesVisible(false);
    chart.setVerticalGridLinesVisible(false);
    chart.setAlternativeColumnFillVisible(false);
    chart.setAlternativeRowFillVisible(false);
    final XYChart.Series<Number, Number> series = new XYChart.Series<Number, Number>();
    series.getData().addAll(
            new XYChart.Data<Number, Number>(0, 950),
            new XYChart.Data<Number, Number>(2000, 100),
            new XYChart.Data<Number, Number>(5000, 200),
            new XYChart.Data<Number, Number>(7500, 180),
            new XYChart.Data<Number, Number>(10000, 100));
    chart.getData().add(series);
    String curveFittedChartCss = CurveFittedAreaChartSample.class.getResource("CurveFittedChart.css").toExternalForm();
    chart.getStylesheets().add(curveFittedChartCss);
    getChildren().add(chart);
}
 
Example 19
Project: marathonv5   File: AdvCandleStickChartSample.java   View source code 6 votes vote down vote up
@Override protected void seriesRemoved(Series<Number, Number> series) {
    // remove all candle nodes
    for (XYChart.Data<Number, Number> d : series.getData()) {
        final Node candle = d.getNode();
        if (shouldAnimate()) {
            // fade out old candle
            FadeTransition ft = new FadeTransition(Duration.millis(500), candle);
            ft.setToValue(0);
            ft.setOnFinished(new EventHandler<ActionEvent>() {

                @Override
                public void handle(ActionEvent actionEvent) {
                    getPlotChildren().remove(candle);
                }
            });
            ft.play();
        } else {
            getPlotChildren().remove(candle);
        }
    }
}
 
Example 20
Project: marathonv5   File: AdvBarAudioChartSample.java   View source code 6 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 21
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 22
Project: Quantify   File: QuantifyStatisticsController.java   View source code 6 votes vote down vote up
@SuppressWarnings("unchecked")
public void setQuantifyData(Data data) {

    List<String> x = new ArrayList<>();
    for (int i = 1; i <= data.getBeforeData().size(); i++) {
        x.add(i + "");
    }
    originData.addAll(x);
    xAxis.setCategories(originData);
    barChart.setBarGap(3);
    XYChart.Series<String, Integer> series1 = new XYChart.Series<>();
    series1.setName("量化前");
    XYChart.Series<String, Integer> series2 = new XYChart.Series<>();
    series2.setName("量化后");
    XYChart.Series<String, Integer> series3 = new XYChart.Series<>();
    series3.setName("差  值");

    for (int i = 0; i < x.size(); i++) {
        series1.getData().add(new XYChart.Data<>(x.get(i), data.getBeforeData().get(i)));
        series2.getData().add(new XYChart.Data<>(x.get(i), data.getAfterData().get(i)));
        series3.getData().add(new XYChart.Data<>(x.get(i), data.getDifferenceData().get(i)));
    }

    barChart.getData().addAll(series1, series2, series3);
}
 
Example 23
Project: javafx-chart-zooming   File: ZoomManager.java   View source code 6 votes vote down vote up
static <X, Y> ObservableList<XYChart.Data<X, Y>> deepCopySeriesData(
		final Collection<? extends XYChart.Data<X, Y>> data) {
	final ObservableList<XYChart.Data<X, Y>> result = FXCollections.observableArrayList();
	for (final Data<X, Y> i : data) {
		result.add(new Data<>(i.getXValue(), i.getYValue()));
	}
	return result;
}
 
Example 24
Project: Optics-Simulator   File: CircleIntensityProfile.java   View source code 6 votes vote down vote up
/**
 * plotIntensity updates the chart with the proper central-line intensity profile using the set mmDiameter and
 * mmWavelength fields. It also updates the plot line color to correspond with the wavelength in visible light
 */
private void plotIntensity(){
    series.getData().clear();
    double xMin = computeXMin(mmDiameter, mmWavelength);
    double xMax = computeXMax(mmDiameter, mmWavelength);
    double step = computeStep(mmDiameter, mmWavelength);
    for(double x = xMin; x <= xMax; x += step){
        //System.out.printf("%f, %f\n", x, computeRelativeIntensity(x));
        series.getData().add(new XYChart.Data<Number, Number>(x, computeRelativeIntensity(x)));
    }
    //System.out.printf("\n\n\n\n");
    lineChart.setStyle("CHART_COLOR_1: " + WavelengthToColor.getHex(mmWavelength, 1.0) + ";");



}
 
Example 25
Project: git-rekt   File: BookingsReportScreenController.java   View source code 6 votes vote down vote up
/**
 * Displays on the chart the report data for the selected month.
 */
private void showDataForAllCategories() {
    this.data.clear(); // Clear any existing data

    for(String category : categories) {
        XYChart.Series<String, Number> categoryData;
        categoryData = new XYChart.Series<>();
        categoryData.setName(category);

        for(int i = 1; i <= daysInCurrentMonth.size(); i++) {
            XYChart.Data<String, Number> dayData = new XYChart.Data<>();
            dayData.setXValue(String.valueOf(i));
            double percentBooked = getPercentBookedInCategoryOnDay(category, i);
            dayData.setYValue(percentBooked);
            categoryData.getData().add(dayData);
        }
        this.data.add(categoryData);
    }
    lineChart.setData(this.data);
}
 
Example 26
Project: java-ml-projects   File: Clustering.java   View source code 6 votes vote down vote up
private List<Series<Number, Number>> buildClusteredSeries() throws Exception {
	List<XYChart.Series<Number, Number>> clusteredSeries = new ArrayList<>();

	// to build the cluster we remove the class information
	Remove remove = new Remove();
	remove.setAttributeIndices("3");
	remove.setInputFormat(data);
	Instances dataToBeClustered = Filter.useFilter(data, remove);

	SimpleKMeans kmeans = new SimpleKMeans();
	kmeans.setSeed(10);
	kmeans.setPreserveInstancesOrder(true);
	kmeans.setNumClusters(3);
	kmeans.buildClusterer(dataToBeClustered);

	IntStream.range(0, 3).mapToObj(i -> {
		Series<Number, Number> newSeries = new XYChart.Series<>();
		newSeries.setName(String.valueOf(i));
		return newSeries;
	}).forEach(clusteredSeries::add);

	int[] assignments = kmeans.getAssignments();
	for (int i = 0; i < assignments.length; i++) {
		int clusterNum = assignments[i];
		clusteredSeries.get(clusterNum).getData().add(instancetoChartData(data.get(i)));
	}

	return clusteredSeries;
}
 
Example 27
Project: shuffleboard   File: GraphWidget.java   View source code 6 votes vote down vote up
private void updateSeries(XYChart.Series<Number, Number> series, long now, double newData) {
  long elapsed = now - Time.getStartTime();
  XYChart.Data<Number, Number> point = new XYChart.Data<>(elapsed, newData);
  ObservableList<XYChart.Data<Number, Number>> dataList = series.getData();
  if (!dataList.isEmpty()) {
    // Make the graph a square wave
    // This prevents the graph from appearing to be continuous when the data is discreet
    // Note this only affects the chart; the actual data is not changed
    double prev = dataList.get(dataList.size() - 1).getYValue().doubleValue();
    if (prev != newData) {
      dataList.add(new XYChart.Data<>(elapsed - 1, prev));
    }
  }
  dataList.add(point);
  realData.computeIfAbsent(series, __ -> FXCollections.observableArrayList()).add(point);
  if (!chart.getData().contains(series)
      && Optional.ofNullable(visibleSeries.get(series)).map(Property::getValue).orElse(true)) {
    chart.getData().add(series);
  }
  updateBounds(elapsed);
}
 
Example 28
Project: shuffleboard   File: GraphWidget.java   View source code 6 votes vote down vote up
private List<XYChart.Series<Number, Number>> getArraySeries(DataSource<double[]> source) {
  List<XYChart.Series<Number, Number>> series = arraySeriesMap.computeIfAbsent(source, __ -> new ArrayList<>());
  final double[] data = source.getData();
  if (data.length < series.size()) {
    while (series.size() != data.length) {
      XYChart.Series<Number, Number> removed = series.remove(series.size() - 1);
      realData.remove(removed);
      visibleSeries.remove(removed);
    }
  } else if (data.length > series.size()) {
    for (int i = series.size(); i < data.length; i++) {
      XYChart.Series<Number, Number> newSeries = new XYChart.Series<>();
      newSeries.setName(source.getName() + "[" + i + "]"); // eg "array[0]", "array[1]", etc
      series.add(newSeries);
      realData.put(newSeries, FXCollections.observableArrayList());
      visibleSeries.computeIfAbsent(newSeries, createVisibleProperty);
    }
  }
  return series;
}
 
Example 29
Project: Recordian   File: CompanyBarChart.java   View source code 5 votes vote down vote up
@Override
XYChart.Series<String, Number> barChartData() {
    XYChart.Series<String, Number> series = new XYChart.Series<>();
    List<Company> companies = companyMapper.readAll();
    Integer timesWorkedForCompany;
    for (Company company : companies) {
        timesWorkedForCompany = getNumberOfLogEntriesContainingSpecifiedDatabaseItem(company.getCompanyName());
        series.getData().add(new XYChart.Data<>(company.getCompanyName(), timesWorkedForCompany));
    }
    return series;
}
 
Example 30
Project: Java-oscilloscope-project   File: ZoomManager.java   View source code 5 votes vote down vote up
private synchronized void restoreData() {
    // make a tmp variable of data, since we will modify it but need to be
    // able to restore
    final ObservableList<XYChart.Series<X, Y>> backup2 = deepCopySeries(series);
    chart.getData().setAll(backup2);

}
 
Example 31
Project: Recordian   File: SupervisorBarChart.java   View source code 5 votes vote down vote up
@Override
XYChart.Series<String, Number> barChartData() {
    XYChart.Series<String, Number> series = new XYChart.Series<>();
    List<Supervisor> supervisors = supervisorMapper.readAll();
    Integer timesWorkedUnderSupervisor;
    for (Supervisor supervisor : supervisors) {
        timesWorkedUnderSupervisor = getNumberOfLogEntriesContainingSpecifiedDatabaseItem(supervisor.getSupervisorDisplayName());
        series.getData().add(new XYChart.Data<>(supervisor.getSupervisorDisplayName(), timesWorkedUnderSupervisor));
    }
    return series;
}
 
Example 32
Project: Recordian   File: LocationBarChart.java   View source code 5 votes vote down vote up
@Override
XYChart.Series<String, Number> barChartData() {
    XYChart.Series<String, Number> series = new XYChart.Series<>();
    List<Location> locations = locationMapper.readAll();
    Integer timesWorkedAtLocation;
    for (Location location : locations) {
        timesWorkedAtLocation = getNumberOfLogEntriesContainingSpecifiedDatabaseItem(location.getLocationName());
        series.getData().add(new XYChart.Data<>(location.getLocationName(), timesWorkedAtLocation));
    }
    return series;
}
 
Example 33
Project: Lernkartei_2017   File: StatisticsModel.java   View source code 5 votes vote down vote up
public ObservableList<XYChart.Series<String, Number>> getObservableDiagrammList (String query)
{
	if (query.equals("saulendiagramm"))
	{
		Debugger.out("StatisticsModel 1");
		return Diagramm.getChartData();
	}
	else
	{
		return null;
	}
}
 
Example 34
Project: Lernkartei_2017   File: Diagramm.java   View source code 5 votes vote down vote up
public static ObservableList<XYChart.Series<String, Number>> getChartData()
{
	Debugger.out("Diagramm getChartData says : Hello ! ");
		if (Data != null || Data.get(0).equals(null))
		{
			resetData();
		} else
		{
			Logger.out("ObservableList Data in Diagramm is already empty");
		}

		getKarteien();
		getPunkte();

		for (int i = 0; i < Stacks.size(); i++)
		{
			Series<String, Number> thisSerie = new Series<String, Number>();
			thisSerie.setName(Stacks.get(i));
			Number forChart = (Number) Punkte.get(i);
			thisSerie.getData().add(new Data<String, Number>(Stacks.get(i), forChart));
			Data.add(thisSerie);
		}
	return Data;
}
 
Example 35
Project: Machine-Learning-End-to-Endguide-for-Java-developers   File: ScatterChart - MainApp.java   View source code 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 36
Project: HueSense   File: TempSensor.java   View source code 5 votes vote down vote up
public TempSensor(int id, String uniqueID, HueSenseConfig config, DBManager dbMan) {
    super(id, uniqueID, SensorType.TEMPERATURE, config, dbMan);
    data = new XYChart.Series<>();
    data.setName("Temperature");
    graphInterval = new SimpleObjectProperty<>(GraphInterval.INTERVALS.get(1));
    tempOffset = new SimpleObjectProperty<>(BigDecimal.ZERO);
    if (config.getString(Constants.TEMP_OFFSET_SENSOR + id) != null) {
        tempOffset.set(new BigDecimal(config.getString(Constants.TEMP_OFFSET_SENSOR + id)));
    }
    tempOffset.addListener((observable, oldValue, newValue) -> {
        changeTempOffset();
    });

}
 
Example 37
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 38
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 39
Project: Java-oscilloscope-project   File: ZoomManager.java   View source code 5 votes vote down vote up
private void doZoom(final boolean x, final Number n1, final Number n2) {
    final double min = Math.min(n1.doubleValue(), n2.doubleValue());
    final double max = Math.max(n1.doubleValue(), n2.doubleValue());
    if (max - min > 1) {
        zoomed = true;
        final Iterator<XYChart.Series<X, Y>> it = chart.getData().iterator();
        while (it.hasNext()) {
            final XYChart.Series<X, Y> s = it.next();
            final Iterator<XYChart.Data<X, Y>> it2 = s.getData().iterator();
            while (it2.hasNext()) {
                final XYChart.Data<X, Y> d = it2.next();
                final Object value;
                if (x) {
                    value = d.getXValue();
                } else {
                    value = d.getYValue();
                }
                if (value instanceof Number) {
                    final Number n = (Number) value;
                    final double dd = n.doubleValue();
                    if (dd < min || dd > max) {
                        it2.remove();
                    } else {
                    }
                }
                if (s.getData().isEmpty()) {
                    it.remove();
                }
            }
        }
    } else {
        // System.out.println("Skip tiny zoom");
    }

}
 
Example 40
Project: pcstatus   File: StackedAreaChartClass.java   View source code 5 votes vote down vote up
/**
 * the constructor is responsible for initialize the chart (lower and upper buonds, name, colors)
 * @param stackedAreaChart is the type of chart for battery performance
 */
public StackedAreaChartClass(StackedAreaChart stackedAreaChart){
    NumberAxis yaxis = (NumberAxis) stackedAreaChart.getYAxis();

    //getter and setting proprieties for y and x axes
    xAxis = (NumberAxis) stackedAreaChart.getXAxis();
    xAxis.setLowerBound(0);
    xAxis.setUpperBound(10);
    xAxis.setAutoRanging(false);
    xAxis.setTickLabelsVisible(false); //hide numbers on x axis
    stackedAreaChart.setVerticalGridLinesVisible(false);//hide vertical lines
    stackedAreaChart.animatedProperty().setValue(false);
    yaxis.setAutoRanging(false);
    yaxis.setLowerBound(0);
    yaxis.setUpperBound(100);

    //set series of content to draw chart
    series = new XYChart.Series();
    series.setName("Battery level");
    stackedAreaChart.getData().add(series);

    //setting colors of charts
    Node fill = series.getNode().lookup(".chart-series-area-fill");
    fill.setStyle("-fx-fill: #fff7ad;");
    Node line = series.getNode().lookup(".chart-series-area-line");
    line.setStyle("-fx-stroke: #8bc34a;" +
            "-fx-stroke-width: 3px;"); // set width of line
    stackedAreaChart.setStyle("CHART_COLOR_1: #8bc34a;"); //color of dots
}