List of usage examples for javafx.scene.chart XYChart.Series getData
public final ObservableList<Series<X, Y>> getData()
From source file:de.perdoctus.ebikeconnect.gui.ActivitiesOverviewController.java
private void addChartSeries(final String title, final List<? extends Number> samples) { logger.info(title + ": " + samples.size() + " samples."); final XYChart.Series<Number, Number> series = new XYChart.Series<>(); series.setName(title);/* w w w . ja va 2s .c o m*/ final ObservableList<XYChart.Data<Number, Number>> data = series.getData(); for (int i = 0; i < samples.size(); i += 4) { final Number number = samples.get(i); if (number != null) { final XYChart.Data<Number, Number> dataPoint = new XYChart.Data<>(i, number); data.add(dataPoint); } } chartRangeSlider.setMax(samples.size()); if (data.size() > 0) { chart.getData().add(series); } }
From source file:ijfx.ui.plugin.overlay.OverlayPanel.java
protected XYChart.Series<Double, Double> getLineChartSerie(Overlay overlay) { Double[] valueList = statsService.getValueListFromImageDisplay(currentDisplay(), overlay); ArrayList<Data<Double, Double>> data = new ArrayList<>(valueList.length); for (int i = 0; i != valueList.length; i++) { data.add(new Data<>(new Double(i), valueList[i])); }//from w ww . java 2 s .c o m XYChart.Series<Double, Double> serie = new XYChart.Series<>(); serie.getData().addAll(data); return serie; }
From source file:ijfx.ui.filter.DefaultNumberFilter.java
public void updateChart() { final double min; // minimum value final double max; // maximum value double range; // max - min final double binSize; int maximumBinNumber = 30; int finalBinNumber; int differentValuesCount = possibleValues.stream().filter(n -> Double.isFinite(n.doubleValue())) .collect(Collectors.toSet()).size(); if (differentValuesCount < maximumBinNumber) { finalBinNumber = differentValuesCount; } else {// www. ja va2 s .com finalBinNumber = maximumBinNumber; } EmpiricalDistribution distribution = new EmpiricalDistribution(finalBinNumber); double[] values = possibleValues.parallelStream().filter(n -> Double.isFinite(n.doubleValue())) .mapToDouble(v -> v.doubleValue()).sorted().toArray(); distribution.load(values); min = values[0]; max = values[values.length - 1]; range = max - min; binSize = range / (finalBinNumber - 1); XYChart.Series<Double, Double> serie = new XYChart.Series<>(); ArrayList<Data<Double, Double>> data = new ArrayList<>(); double k = min; for (SummaryStatistics st : distribution.getBinStats()) { data.add(new Data<>(k, new Double(st.getN()))); k += binSize; } Platform.runLater(() -> { serie.getData().addAll(data); areaChart.getData().clear(); areaChart.getData().add(serie); updateSlider(min, max, finalBinNumber); }); }
From source file:ijfx.ui.plugin.panel.OverlayPanel.java
protected XYChart.Series<Double, Double> getOverlayHistogram(Overlay overlay) { Timer timer = timerService.getTimer(this.getClass()); timer.start();//from w ww. j a va 2s . co m Double[] valueList = statsService.getValueList(currentDisplay(), overlay); timer.elapsed("Getting the stats"); SummaryStatistics sumup = new SummaryStatistics(); for (Double v : valueList) { sumup.addValue(v); } timer.elapsed("Building the sumup"); double min = sumup.getMin(); double max = sumup.getMax(); double range = max - min; int bins = 100;//new Double(max - min).intValue(); EmpiricalDistribution distribution = new EmpiricalDistribution(bins); double[] values = ArrayUtils.toPrimitive(valueList); Arrays.parallelSort(values); distribution.load(values); timer.elapsed("Sort and distrubution repartition up"); XYChart.Series<Double, Double> serie = new XYChart.Series<>(); ArrayList<Data<Double, Double>> data = new ArrayList<>(bins); double k = min; for (SummaryStatistics st : distribution.getBinStats()) { data.add(new Data<Double, Double>(k, new Double(st.getN()))); k += range / bins; } serie.getData().clear(); serie.getData().addAll(data); timer.elapsed("Creating charts"); return serie; }
From source file:ijfx.ui.plugin.overlay.OverlayPanel.java
protected XYChart.Series<Double, Double> getOverlayHistogram(Overlay overlay) { Timer timer = timerService.getTimer(this.getClass()); timer.start();//from w ww . j a v a2 s .c om Double[] valueList = statsService.getValueListFromImageDisplay(currentDisplay(), overlay); timer.elapsed("Getting the stats"); SummaryStatistics sumup = new SummaryStatistics(); for (Double v : valueList) { sumup.addValue(v); } timer.elapsed("Building the sumup"); double min = sumup.getMin(); double max = sumup.getMax(); double range = max - min; int bins = 100;//new Double(max - min).intValue(); EmpiricalDistribution distribution = new EmpiricalDistribution(bins); double[] values = ArrayUtils.toPrimitive(valueList); Arrays.parallelSort(values); distribution.load(values); timer.elapsed("Sort and distrubution repartition up"); XYChart.Series<Double, Double> serie = new XYChart.Series<>(); ArrayList<Data<Double, Double>> data = new ArrayList<>(bins); double k = min; for (SummaryStatistics st : distribution.getBinStats()) { data.add(new Data<Double, Double>(k, new Double(st.getN()))); k += range / bins; } serie.getData().clear(); serie.getData().addAll(data); timer.elapsed("Creating charts"); return serie; }
From source file:magicdeckmanager.card.CardManager.java
public XYChart.Series getManaCostBarChartData(DeckData deckData) { XYChart.Series result = new XYChart.Series(); result.setName("Mana Cost"); Map<Integer, Integer> costQuantity = new HashMap<>(); final List<String> main = deckData.getMain(); for (String cardName : main) { Card card = getCardFromName(cardName); if (!card.isLand()) { Integer cmc = card.cmc; Integer quantity = costQuantity.get(cmc); if (quantity != null) { quantity++;//from w w w . j av a2 s .c o m } else { quantity = 1; } costQuantity.put(cmc, quantity); } } for (Map.Entry<Integer, Integer> entrySet : costQuantity.entrySet()) { Integer key = entrySet.getKey(); Integer value = entrySet.getValue(); result.getData().add(new XYChart.Data("CC" + key.toString(), value)); } return result; }
From source file:com.jscriptive.moneyfx.ui.chart.ChartFrame.java
/** * This method is invoked when the daily balance button has been toggled * * @param actionEvent/*from ww w.ja v a 2 s. com*/ */ public void dailyBalanceToggled(ActionEvent actionEvent) { LocalDateAxis xAxis = new LocalDateAxis(); NumberAxis yAxis = new NumberAxis(); final LineChart<LocalDate, Number> lineChart = new LineChart<>(xAxis, yAxis); lineChart.setCreateSymbols(false); chartFrame.setCenter(lineChart); ToggleButton toggle = (ToggleButton) actionEvent.getTarget(); if (toggle.isSelected()) { xAxis.setLabel("Day of year"); yAxis.setLabel("Balance in Euro"); lineChart.setTitle("Balance development day by day"); ValueRange<LocalDate> period = getTransactionOpRange(accountCombo.getValue(), yearCombo.getValue()); if (period.isEmpty()) { return; } xAxis.setLowerBound(period.from()); xAxis.setUpperBound(period.to()); Service<Void> service = new Service<Void>() { @Override protected Task<Void> createTask() { return new Task<Void>() { @Override protected Void call() throws Exception { Map<Account, List<Transaction>> transactionMap = getTransactions( accountCombo.getValue(), yearCombo.getValue()); transactionMap.entrySet().forEach(entry -> { Account account = entry.getKey(); List<Transaction> transactionList = entry.getValue(); XYChart.Series<LocalDate, Number> series = new XYChart.Series<>(); series.setName(format("%s [%s]", account.toPresentableString(), account.getFormattedBalance())); // sort transactions by operation value descending transactionList.sort((t1, t2) -> t2.getDtOp().compareTo(t1.getDtOp())); account.calculateStartingBalance(transactionList); series.getData() .add(new XYChart.Data<>(account.getBalanceDate(), account.getBalance())); // sort transactions by operation value ascending transactionList.sort((t1, t2) -> t1.getDtOp().compareTo(t2.getDtOp())); transactionList.forEach(trx -> { account.calculateCurrentBalance(trx); series.getData().add( new XYChart.Data<>(account.getBalanceDate(), account.getBalance())); }); Platform.runLater(() -> lineChart.getData().add(series)); }); return null; } }; } }; service.start(); } }
From source file:de.ifsr.adam.ImageGenerator.java
/** * Creates the data series needed for creating a bar chart. * * @param result The result JSONObject you wish to transform * @param answerType The answer type JSONObject of the question * @return/*from w ww. ja v a2s .c o m*/ */ private XYChart.Series generateDataBarChart(JSONObject result, JSONObject answerType) { XYChart.Series series = new XYChart.Series(); try { JSONObject answers; String[] fieldNames; try { answers = answerType.getJSONObject("answers"); fieldNames = JSONObject.getNames(answers); } catch (NullPointerException e) { log.error("Missing JSONObject in result:" + result + " answerType: " + answerType); log.debug("", e); return series; } for (int i = 1; i < fieldNames.length; i++) { //i initialized with 1 to ignore the empty string result String answer = answers.getString(fieldNames[i]); Integer value; try { value = result.getInt(fieldNames[i]); } catch (JSONException e) { value = 0; } series.getData().add(new XYChart.Data(value, answer)); } } catch (JSONException e) { log.error(e); } return series; }
From source file:org.specvis.view.screenandlumscale.ViewFitLumScaleController.java
private void initLineChart() { // 1. Define axes. NumberAxis xAxis = new NumberAxis(); NumberAxis yAxis = new NumberAxis(); xAxis.setLabel("HSB Brightness (%)"); yAxis.setLabel("Luminance (cd/m2)"); // 2. Init lineChart. lineChart = new LineChart<>(xAxis, yAxis); lineChart.setTitle("Screen luminance scale"); // 3. Define chart series. XYChart.Series seriesFittedLuminance = new XYChart.Series(); seriesFittedLuminance.setName("Fitted luminance"); XYChart.Series seriesMeasuredLuminance = new XYChart.Series(); seriesMeasuredLuminance.setName("Measured luminance"); // 4. Get luminance scale. LuminanceScale luminanceScale;/*w w w . j a v a2 s .co m*/ if (StartApplication.getSpecvisData().getUiSettingsScreenAndLuminanceScale() .isThisWindowOpenedForStimulus()) { luminanceScale = StartApplication.getSpecvisData().getUiSettingsScreenAndLuminanceScale() .getStimulusLuminanceScale(); } else { luminanceScale = StartApplication.getSpecvisData().getUiSettingsScreenAndLuminanceScale() .getBackgroundLuminanceScale(); } // 5. Create short brightness vector. double[] shortBrightnessVector = new double[] { 0, 20, 40, 60, 80, 100 }; // 6. Get measured luminance values. double[] measuredLuminances = new double[] { luminanceScale.getLuminanceForBrightness0(), luminanceScale.getLuminanceForBrightness20(), luminanceScale.getLuminanceForBrightness40(), luminanceScale.getLuminanceForBrightness60(), luminanceScale.getLuminanceForBrightness80(), luminanceScale.getLuminanceForBrightness100() }; // 7. Create full brightness vector. double[] fullBrightnessVector = functions.createBrightnessVector(101); // 8. Nest data in series. for (int i = 0; i < fullBrightnessVector.length; i++) { seriesFittedLuminance.getData().add(new XYChart.Data(fullBrightnessVector[i], luminanceScale.getFittedLuminanceForEachBrightnessValue()[i])); } for (int i = 0; i < shortBrightnessVector.length; i++) { seriesMeasuredLuminance.getData() .add(new XYChart.Data(shortBrightnessVector[i], measuredLuminances[i])); } // 9. Add series to lineChart. lineChart.getData().addAll(seriesFittedLuminance, seriesMeasuredLuminance); vBox.getChildren().remove(vBox.getChildren().size() - 1); vBox.getChildren().add(lineChart); VBox.setVgrow(lineChart, Priority.ALWAYS); }
From source file:UI.MainStageController.java
/** * collects the data for the barChart//from www.j av a 2s .co m * data includes: * degree distribution * hubs */ public void displayGraphAnalysis() { //Generate Data for the BarChart GraphAnalysis analysis = AnalysisData.getAnalysis(); HashMap<Integer, Double> degreeDistribution = analysis.getDegreeDistribution(); XYChart.Series<String, Double> degreeSeries = new XYChart.Series<>(); for (Map.Entry<Integer, Double> entry : degreeDistribution.entrySet()) { degreeSeries.getData().add(new XYChart.Data<>(entry.getKey().toString(), entry.getValue())); } degreeDistributionChart.getData().clear(); degreeDistributionChart.getData().add(degreeSeries); //Generate Graph Statistics to display in the TextArea HashMap<TaxonNode, Integer> hubs = analysis.getHubsList(); graphStatText.setText("List of Hubs:\n\n"); //Sort hubs by descending values Map<TaxonNode, Integer> hubsSorted = hubs.entrySet().stream() .sorted(Map.Entry.comparingByValue(Collections.reverseOrder())).collect(Collectors .toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new)); for (Map.Entry<TaxonNode, Integer> entry : hubsSorted.entrySet()) { graphStatText .setText(graphStatText.getText() + entry.getKey().getName() + " (" + entry.getValue() + ")\n"); } }