create JavaFX Chart Number Series - Java JavaFX

Java examples for JavaFX:Chart

Description

create JavaFX Chart Number Series

Demo Code


//package com.java2s;
import javafx.scene.chart.XYChart;

public class Main {
    public static void main(String[] argv) throws Exception {
        int[] data = new int[] { 34, 35, 36, 37, 37, 37, 67, 68, 69 };
        System.out.println(createNumberSeries(data));
    }// w ww  .  j a va2 s  .co  m

    public static XYChart.Series<Number, Number> createNumberSeries(
            int[] data) {
        return createNumberSeries(data, 1);
    }

    public static XYChart.Series<Number, Number> createNumberSeries(
            int[] data, int rate) {
        XYChart.Series<Number, Number> series = new XYChart.Series<>();
        for (int i = 0; i < data.length; i = i + rate) {
            series.getData().add(new XYChart.Data<>(i, data[i]));
        }
        return series;
    }

    public static XYChart.Series<Number, Number> createNumberSeries(
            double[] data) {
        return createNumberSeries(data, 1);
    }

    public static XYChart.Series<Number, Number> createNumberSeries(
            double[] data, int rate) {
        XYChart.Series<Number, Number> series = new XYChart.Series<>();
        for (int i = 0; i < data.length; i = i + rate) {
            series.getData().add(new XYChart.Data<>(i, data[i]));
        }
        return series;
    }
}

Related Tutorials