Java Code Examples for javafx.scene.chart.XYChart#Series

The following examples show how to use javafx.scene.chart.XYChart#Series . 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: AdvancedAreaChartSample.java    From marathonv5 with Apache License 2.0 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 2
Source File: CandleStickChart.java    From bisq with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected void dataItemRemoved(XYChart.Data<Number, Number> item, XYChart.Series<Number, Number> series) {
    if (series.getNode() instanceof Path) {
        Path seriesPath = (Path) series.getNode();
        seriesPath.getElements().clear();
    }

    final Node node = item.getNode();
    if (shouldAnimate()) {
        // fade out old candle
        FadeTransition ft = new FadeTransition(Duration.millis(500), node);
        ft.setToValue(0);
        ft.setOnFinished((ActionEvent actionEvent) -> {
            getPlotChildren().remove(node);
            removeDataItemFromDisplay(series, item);
        });
        ft.play();
    } else {
        getPlotChildren().remove(node);
        removeDataItemFromDisplay(series, item);
    }
}
 
Example 3
Source File: AdvancedBubbleChartSample.java    From marathonv5 with Apache License 2.0 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 4
Source File: ChartAdvancedArea.java    From netbeans with Apache License 2.0 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 5
Source File: BreakingNewsDemo.java    From htm.java-examples with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Updates the chart with a new series entry.
 *
 * @param tweet
 * @param result
 */
private void updateChart(Tweet tweet, double result) {
    String[] dateStr = TweetUtilities.getJsonNode(tweet.getJson()).get("created_at").asText().split("\\s");
    String day = dateStr[0].concat(", ").concat(dateStr[1]).concat(" ").concat(dateStr[2]);
    String time = dateStr[3];

    XYChart.Series<String, Number> series = view.chartSeriesProperty().get();
    if(series.getData().size() == 6) {
        series.getData().remove(0);
    }
    series.getData().add(new XYChart.Data<String, Number>(day +"\n" + time, result));
}
 
Example 6
Source File: SeriesChartTableCellFactory.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
@Override public void updateItem(List<Double> item, boolean empty) {
    super.updateItem(item, empty);

    if (empty) {
        setGraphic(null);
    } else {
        XYChart.Series<Number, Number> salesSeries = new XYChart.Series<Number, Number>();
        for (int i = 0; i < item.size(); i++) {
            salesSeries.getData().add(new XYChart.Data<Number, Number>(i, item.get(i)));
        }
        chart.getData().setAll(salesSeries);
        setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
    }
}
 
Example 7
Source File: ChartUtil.java    From DevToolBox with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void changeChart(LineChart chart, Date now, Double dt, String name) {
    ObservableList<XYChart.Series> data = chart.getData();
    XYChart.Series xys = null;
    if (data.isEmpty()) {
        xys = getSeries(chart, dt, name);
        data.add(xys);
        addClickListener(chart);
    } else {
        boolean exits = false;
        for (XYChart.Series series : data) {
            if (name.equals(series.getName())) {
                exits = true;
                xys = series;
                break;
            }
        }
        if (!exits) {
            xys = getSeries(chart, dt, name);
            data.add(xys);
            addClickListener(chart);
        }
        NumberAxis na = (NumberAxis) chart.getYAxis();
        na.setUpperBound(Math.max(na.getUpperBound(), dt));
    }
    XYChart.Data xdata = new XYChart.Data<>(DATE_FORMAT.format(now), dt);
    xdata.setNode(new HoveredThresholdNode(dt, dt));
    xdata.getNode().setVisible(CACHE.get(name) == null ? true : CACHE.get(name));
    xys.getData().add(xdata);
    if (xys.getData().size() > 9) {
        xys.getData().remove(0);
    }
}
 
Example 8
Source File: AdvancedBarChartSample.java    From marathonv5 with Apache License 2.0 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 9
Source File: Demo.java    From Enzo with Apache License 2.0 5 votes vote down vote up
@Override public void init() {
    XYChart.Series series = new XYChart.Series();
    series.setName("temperature");
    series.getData().add(new XYChart.Data("7:00", 27.3));
    series.getData().add(new XYChart.Data("8:00", 28.2));
    series.getData().add(new XYChart.Data("9:00", 28.5));
    series.getData().add(new XYChart.Data("10:00", 29.2));
    series.getData().add(new XYChart.Data("11:00", 29.6));
    series.getData().add(new XYChart.Data("12:00", 31.5));
    series.getData().add(new XYChart.Data("13:00", 32.0));
    series.getData().add(new XYChart.Data("14:00", 31.2));
    series.getData().add(new XYChart.Data("15:00", 30.2));
    series.getData().add(new XYChart.Data("16:00", 29.68));
    series.getData().add(new XYChart.Data("17:00", 30.05));
    series.getData().add(new XYChart.Data("18:00", 31.25));

    chart = new SimpleLineChart();
    chart.setSections(new Section[]{
        new Section(0, 10),
        new Section(10, 15),
        new Section(15, 25),
        new Section(25, 30),
        new Section(30, 40)
    });
    chart.getStyleClass().addAll(SimpleLineChart.STYLE_CLASS_BLUE_TO_RED_5);
    chart.setSectionRangeVisible(true);
    chart.setUnit("°C");
    chart.setSeries(series);
}
 
Example 10
Source File: AdvancedStockLineChartSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
protected LineChart<Number, Number> createChart() {
    xAxis = new NumberAxis(0,24,3);
    final NumberAxis yAxis = new NumberAxis(0,100,10);
    final LineChart<Number,Number> lc = new LineChart<Number,Number>(xAxis,yAxis);
    // setup chart
    lc.setId("lineStockDemo");
    lc.setCreateSymbols(false);
    lc.setAnimated(false);
    lc.setLegendVisible(false);
    lc.setTitle("ACME Company Stock");
    xAxis.setLabel("Time");
    xAxis.setForceZeroInRange(false);
    yAxis.setLabel("Share Price");
    yAxis.setTickLabelFormatter(new NumberAxis.DefaultFormatter(yAxis,"$",null));
    // add starting data
    hourDataSeries = new XYChart.Series<Number,Number>();
    hourDataSeries.setName("Hourly Data");
    minuteDataSeries = new XYChart.Series<Number,Number>();
    minuteDataSeries.setName("Minute Data");
    // create some starting data
    hourDataSeries.getData().add(new XYChart.Data<Number,Number>(timeInHours,prevY));
    minuteDataSeries.getData().add(new XYChart.Data<Number,Number>(timeInHours,prevY));
    for (double m=0; m<(60); m++) {
        nextTime();
        plotTime();
    }
    lc.getData().add(minuteDataSeries);
    lc.getData().add(hourDataSeries);
    return lc;
}
 
Example 11
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 12
Source File: ChartAdvancedBar.java    From netbeans with Apache License 2.0 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 13
Source File: MainWindow.java    From quantumjava with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private ObservableList<XYChart.Series<String, Integer>> getChartData(int[] results) {
    ObservableList<XYChart.Series<String, Integer>> answer = FXCollections.observableArrayList();
    XYChart.Series<String, Integer> series = new XYChart.Series<>();
    answer.add(series);
    for (int i = 0; i < results.length;i++) {
        series.getData().add(new XYChart.Data<>(getFixedBinaryString(i, (int) (Math.log(results.length)/Math.log(2))), results[i]));
    }
    return answer;
}
 
Example 14
Source File: SmoothedChart.java    From tilesfx with Apache License 2.0 5 votes vote down vote up
public void setSeriesColor(final XYChart.Series<X, Y> SERIES, final Paint STROKE, final Paint FILL, final Background SYMBOL_BACKGROUND, final Paint LEGEND_SYMBOL_FILL) {
    if (getData().isEmpty()) { return; }
    if (!getData().contains(SERIES)) { return; }
    if (null != FILL)               { ((Path) ((Group) SERIES.getNode()).getChildren().get(0)).setFill(FILL); }
    if (null != STROKE)             { ((Path) ((Group) SERIES.getNode()).getChildren().get(1)).setStroke(STROKE); }
    if (null != SYMBOL_BACKGROUND)  { setSymbolFill(SERIES, SYMBOL_BACKGROUND); }
    // If enabled the following line won't work in Java 9 because it makes use of com.sun packages!!!
    //if (null != LEGEND_SYMBOL_FILL) { setLegendSymbolFill(SERIES, LEGEND_SYMBOL_FILL); }
}
 
Example 15
Source File: IndexChart - MainApp.java    From Java-for-Data-Science with MIT License 4 votes vote down vote up
public void addDataItem(XYChart.Series<String, Number> series,
        String x, Number y) {
    series.getData().add(new XYChart.Data<>(x, y));
}
 
Example 16
Source File: ReportsController.java    From HealthPlus with Apache License 2.0 4 votes vote down vote up
@FXML private void genericNameSelect()
{
    try{
        String selectedDrug = genericNameSelectCombo.getSelectionModel().getSelectedItem().toString();

        if (selectedDrug.equals("All")) 
        {
            fillStockChart();

        } else {    

            ArrayList<ArrayList<String>> drugs = admin.getStockSummary();
            int noOfSlots = (drugs.size()-1);
            //System.out.println(noOfSlots);
            //System.out.println(currentTimeTableData0);

            HashMap<String,String> drugInfo = admin.getDrugGenericInfo();

            ArrayList<ArrayList<String>> drugNames = admin.getDrugNames();

            System.out.println(drugs);
            System.out.println(drugInfo);


            XYChart.Series<String, Number> series1 = new XYChart.Series();
            //System.out.println(drugInfo);
            int noOfDrugs = drugInfo.size();

            for(int i = 1; i < noOfDrugs+1; i++)
            {
                int brandAmount = 0;
                String brand = drugNames.get(i).get(1);
                System.out.println(brand +" " + drugInfo.get(brand));
                if (selectedDrug.equals(drugInfo.get(brand)))
                {
                    ArrayList<ArrayList<String>> drugBrandAmounts = admin.getDrugAmounts(drugNames.get(i).get(0));

                    System.out.println(selectedDrug);
                    System.out.println(drugBrandAmounts);

                    int size2 = drugBrandAmounts.size();
                    for(int j = 1; j < size2; j++)
                    {
                        brandAmount += Integer.parseInt(drugBrandAmounts.get(j).get(0));
                    }        
                    series1.getData().add(new XYChart.Data(brand , brandAmount));
                }       
            }    

            series1.setName(selectedDrug); 
            stockChart.getData().clear();
            stockChart.getData().add(series1);
            genericNameSelectCombo.setPromptText(selectedDrug);
        }
    }catch(Exception e){} 
}
 
Example 17
Source File: LabAssistantController.java    From HealthPlus with Apache License 2.0 4 votes vote down vote up
public void fillLabAppiontments()
{
    
    HashMap<Integer,String> months = new HashMap<Integer,String>();
    months.put(1,"January");
    months.put(2,"February");
    months.put(3,"March");
    months.put(4,"April");
    months.put(5,"May");
    months.put(6,"June");
    months.put(7,"July");
    months.put(8,"August");
    months.put(9,"September");
    months.put(10,"October");
    months.put(11,"November");
    months.put(12,"December");
    
    
    
    ArrayList<String> data = lab.lastMonthsAppointments();
    int months2 = data.size();
    
    Calendar cal = Calendar.getInstance();
    int month = cal.get(Calendar.MONTH);

    XYChart.Series appointments= new XYChart.Series();
    appointments.setName("Appointments");
    
    int i;
    for(i = (months2-1); i >= 0; i-- )
    {
        int tmp = 0;
        if (month-i > 0 ) tmp = month-i;
        else tmp = 12-i-month;
            
        appointments.getData().add(new XYChart.Data(months.get(tmp), Integer.parseInt(data.get(i))));
    }    

  
    labAppointments.getData().addAll(appointments);


}
 
Example 18
Source File: SmoothedChart.java    From OEE-Designer with MIT License 4 votes vote down vote up
public void setSeriesColor(final XYChart.Series<X, Y> SERIES, final Paint STROKE, final Paint FILL, final Paint LEGEND_SYMBOL_FILL) {
    Background symbolBackground = new Background(new BackgroundFill(STROKE, new CornerRadii(1024), Insets.EMPTY), new BackgroundFill(Color.WHITE, new CornerRadii(1024), new Insets(2)));
    setSeriesColor(SERIES, STROKE, FILL, symbolBackground, LEGEND_SYMBOL_FILL);
}
 
Example 19
Source File: CalcExpController.java    From logbook-kai with MIT License 4 votes vote down vote up
/**
 * チャートを作る
 */
private void chart() {
    int nowExpValue = this.nowExpValue;
    int nowLvValue = this.nowLv.getValue();
    int goalLvValue = this.goalLv.getValue();

    XYChart.Series<Number, Number> total = new XYChart.Series<>();
    XYChart.Series<Number, Number> goal = new XYChart.Series<>();
    XYChart.Series<Number, Number> now = new XYChart.Series<>();

    if (goalLvValue <= 100) {
        total.getData().addAll(ExpTable.get().entrySet()
                .stream()
                .filter(e -> e.getKey() < 100)
                .map(e -> new XYChart.Data<Number, Number>(e.getKey(), e.getValue()))
                .collect(Collectors.toList()));
    } else {
        total.getData().addAll(ExpTable.get().entrySet()
                .stream()
                .map(e -> new XYChart.Data<Number, Number>(e.getKey(), e.getValue()))
                .collect(Collectors.toList()));
    }
    goal.getData().addAll(ExpTable.get().entrySet()
            .stream()
            .filter(e -> e.getKey() <= goalLvValue)
            .map(e -> new XYChart.Data<Number, Number>(e.getKey(), e.getValue()))
            .collect(Collectors.toList()));
    now.getData().addAll(ExpTable.get().entrySet()
            .stream()
            .filter(e -> e.getKey() <= nowLvValue)
            .map(e -> new XYChart.Data<Number, Number>(e.getKey(), e.getValue()))
            .collect(Collectors.toList()));

    if (ExpTable.get().containsKey(nowLvValue + 1)
            && !ExpTable.get().get(nowLvValue).equals(ExpTable.get().get(nowLvValue + 1))) {
        double per = ((double) nowExpValue - ExpTable.get().get(nowLvValue))
                / ((double) ExpTable.get().get(nowLvValue + 1) - ExpTable.get().get(nowLvValue));

        now.getData().add(new XYChart.Data<Number, Number>(nowLvValue + per, nowExpValue));
    }

    this.expChart.getData().clear();
    this.expChart.getData().addAll(Arrays.asList(total, goal, now));
}
 
Example 20
Source File: ResourceChartController.java    From logbook-kai with MIT License 2 votes vote down vote up
/**
 * 高速修復材を取得します。
 * @return 高速修復材
 */
public XYChart.Series<Number, Number> getBucket() {
    return this.bucket;
}