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; }
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; }
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; }
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; }
public MonitorPaneTemplate() { super(); super.getStyleClass().add("pane"); x = new NumberAxis(); x.setAutoRanging(false); y = new NumberAxis(); y.setAutoRanging(false); chart = new LineChart<>(x, y); chart.setCreateSymbols(false); chart.legendVisibleProperty().setValue(false); chart.setPrefHeight(250); chart.setPrefWidth(750); data = new Series<>(); chart.getData().add(data); super.getChildren().add(chart); }
private void swapClusteredChartSeriesColors() { List<Series<Number, Number>> clusteredSeries = new ArrayList<>(); // we have to copy the original data to swap the series clusteredChart.getData().forEach(serie -> { Series<Number, Number> series = new Series<>(); series.setName(serie.getName()); serie.getData().stream().map(d -> new Data<Number, Number>(d.getXValue(), d.getYValue())) .forEach(series.getData()::add); clusteredSeries.add(series); }); int i = swapColorsCombinations[swapIndex][0]; int j = swapColorsCombinations[swapIndex][1]; Collections.swap(clusteredSeries, i, j); clusteredChart.getData().clear(); clusteredChart.getData().addAll(clusteredSeries); swapIndex = swapIndex == NUMBER_OF_CLASSES - 1 ? 0 : swapIndex + 1; }
/** * get the LineChart for this history * @return - the line chart */ @SuppressWarnings("rawtypes") public LineChart<Number, Number> createLineChart() { //defining the axes final NumberAxis xAxis = new NumberAxis(); final NumberAxis yAxis = new NumberAxis(); xAxis.setLabel(xTitle); //creating the chart lineChart = new LineChart<Number,Number>(xAxis,yAxis); lineChart.setTitle(title); for (CANProperty canProperty : this.canProperties.values()) { Series<Number, Number> series = this.createSeries(canProperty); seriesMap.put(canProperty.getName(), series); updateSeries(series,canProperty); lineChart.getData().add(series); } return lineChart; }
@FXML public void initialize() { items.addListener(this); // chart.getData().add(chartSeries); slider.setMin(0D); slider.setMax(displaySize.get()); this.displaySize.bind(slider.maxProperty()); slider.valueProperty().addListener((oba, oldval, newval) -> { int start = newval.intValue(); int end = (int) (start + displaySize.get()); if (end > items.size()) end = items.size(); ObservableList<Data<String, Number>> subList = items.stream().skip(start).limit(5).map(v -> converter.apply(v)) .collect(FxCollectors.toObservableList()); Series<String, Number> chartSeries = new Series<>("", subList); chart.getData().remove(0); chart.getData().add(chartSeries); }); }
@Override public void onChanged(javafx.collections.ListChangeListener.Change<? extends T> c) { if (c.next()) { if (c.wasAdded()) { int start = (int) slider.getValue(); int end = (int) (start + displaySize.get()); Series<String, Number> chartSeries = new Series<>(); chartSeries.getData().addAll(items.subList(start, end).stream().map(v -> converter.apply(v)).collect(Collectors.toList())); chart.getData().add(chartSeries); } else if (c.wasRemoved()) { } this.slider.setMax(items.size()); } }
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; }
@Override public Node drawNode() { final XYChart chart = (XYChart)createObject(); Platform.runLater(new Runnable() { public void run() { int counter = 0; chart.setAnimated(true); for (Series series : data) { if (add) { if (counter > chart.getData().size()) { chart.getData().add(series); } else { chart.getData().add(counter, series); } counter+= 2; } else { if (counter++ < chart.getData().size()) { chart.getData().set(counter, series); } } } } }); return chart; }
@Override public Node drawNode() { final XYChart chart = (XYChart)createObject(); Platform.runLater(new Runnable() { public void run() { chart.setAnimated(true); int overall_counter = 0; end: for (Series series : (ObservableList<Series>)chart.getData()) { int size = series.getData().size(); for (int i = 0; i < size/2; i++) { if (overall_counter >= data.size()) { break end; } if (add) { series.getData().add(i * 2 + 1, data.get(overall_counter++)); } else { series.getData().set(i * 2 + 1, data.get(overall_counter++)); } } } } }); return chart; }
@Override public Node drawNode() { final NumberAxis xAxis = new NumberAxis(); final NumberAxis yAxis = new NumberAxis(); final LineChart<Number, Number> chart = new LineChart<>(xAxis, yAxis); XYChart.Series series = new XYChart.Series(); series.getData().add(new XYChart.Data(8, 45)); series.getData().add(new XYChart.Data(9, 43)); series.getData().add(new XYChart.Data(10, 17)); series.getData().add(new XYChart.Data(11, 29)); series.getData().add(new XYChart.Data(12, 25)); series.getData().add(new XYChart.Data(1, 23)); series.getData().add(new XYChart.Data(2, 14)); series.getData().add(new XYChart.Data(3, 15)); series.getData().add(new XYChart.Data(4, 24)); series.getData().add(new XYChart.Data(5, 34)); series.getData().add(new XYChart.Data(6, 36)); series.getData().add(new XYChart.Data(7, 22)); chart.getData().add(series); return chart; }
public HBox getRemoveDataFromSerieDialog() { HBox hb = new HBox(); Label lb1 = new Label("From serie"); final TextField tf1 = TextFieldBuilder.create().text("0").prefWidth(50).build(); Label lb2 = new Label("from index"); final TextField tf2 = TextFieldBuilder.create().text("0").prefWidth(50).build(); Button bt = ButtonBuilder.create().text("remove point!").id(REMOVE_BUTTON_ID).build(); bt.setOnAction(new EventHandler() { public void handle(Event t) { int serie = Integer.parseInt(tf1.getText()); int index = Integer.parseInt(tf2.getText()); ((Series) testedScatterChart.getData().get(serie)).getData().remove(index); } }); hb.getChildren().addAll(lb1, tf1, lb2, tf2, bt); return hb; }
public HBox getRemovePointFromDataDialog() { HBox hb = new HBox(); Label lb1 = new Label("From area"); final TextField tf1 = TextFieldBuilder.create().text("0").prefWidth(50).id(REMOVE_AREA_POS_TEXT_FIELD_ID).build(); Label lb2 = new Label("From index"); final TextField tf2 = TextFieldBuilder.create().text("0").prefWidth(50).id(REMOVE_INDEX_TEXT_FIELD_ID).build(); Button bt = ButtonBuilder.create().text("remove point!").id(REMOVE_BUTTON_ID).build(); bt.setOnAction(new EventHandler() { public void handle(Event t) { int area = Integer.parseInt(tf1.getText()); int point = Integer.parseInt(tf2.getText()); ((Series) testedAreaChart.getData().get(area)).getData().remove(point); } }); hb.getChildren().addAll(lb1, tf1, lb2, tf2, bt); return hb; }
public HBox getRemoveDataFromSerieDialog() { HBox hb = new HBox(); Label lb1 = new Label("From serie"); final TextField tf1 = TextFieldBuilder.create().text("0").prefWidth(50).build(); Label lb2 = new Label("from index"); final TextField tf2 = TextFieldBuilder.create().text("0").prefWidth(50).build(); Button bt = ButtonBuilder.create().text("remove bubble!").id(REMOVE_BUTTON_ID).build(); bt.setOnAction(new EventHandler() { public void handle(Event t) { int serie = Integer.parseInt(tf1.getText()); int index = Integer.parseInt(tf2.getText()); ((Series) testedBubbleChart.getData().get(serie)).getData().remove(index); } }); hb.getChildren().addAll(lb1, tf1, lb2, tf2, bt); return hb; }
public void setDFTTaps( float[] taps ) { double smallest = 0.0; final XYChart.Series<Number, Number> series = new XYChart.Series<>(); for( int x = 0; x < taps.length; x++ ) { if( taps[ x ] < smallest ) { smallest = taps[ x ]; } series.getData().add( new XYChart.Data<Number, Number>( x, taps[ x ] ) ); } ObservableList<Series<Number,Number>> list = mDFTChart.getData(); list.add( series ); }
private static void plotProjections(ScatterChart<Number, Number> chart, AnchorPane overlay, List<Label> labels, List<Data<Number,Number>> data, Projection[] projections, String name, double[][][] points) { final Series<Number, Number> series = new Series<Number, Number>(); series.setName(name); for (Projection projection: projections) { System.out.print(projection+": "); final double[] params = projection.getDefaultParameters(); final double distortion[] = projection.avgDistortion(points, params); final Data<Number, Number> datum = new Data<Number, Number>( distortion[0]/DECIBEL, distortion[1]/DECIBEL); series.getData().add(datum); final Label lbl = new Label(projection.getName()); overlay.getChildren().add(lbl); labels.add(lbl); data.add(datum); System.out.println(distortion[0]+", "+distortion[1]); } chart.getData().add(series); }
private void createChart() { xAxis = new NumberAxis();// lowerBoundX, upperBoundX, CHART_AXIS_TICK_UNIT); yAxis = new NumberAxis();// lowerBoundY, upperBoundY, CHART_AXIS_TICK_UNIT); chart = new LineChart<>(xAxis, yAxis); xAxis.setLabel("X"); yAxis.setLabel("Y"); final List<XYChart.Series<Number, Number>> seriesList = createChartSeries(); chart.getData().addAll(seriesList); chartPane = new StackPane(chart); VBox.setVgrow(chartPane, Priority.ALWAYS); chartBox.getChildren().add(0, chartPane); addDataItemChangeListener(); addSelectionListener(); addDataImportListener(); }
private void init(final Stage stage) { this.xAxis = this.initXAxis(); this.yAxis = this.initYAxis(); final LineChart<Number, Number> chart = this.initChart(); // Chart Series this.barometricAltitudeSeries = new LineChart.Series<Number, Number>(); this.barometricAltitudeSeries.setName("Barometric Altitude"); chart.getData().add(this.barometricAltitudeSeries); this.estimatedAltitudeSeries = new LineChart.Series<Number, Number>(); this.estimatedAltitudeSeries.setName("Estimated Altitude"); chart.getData().add(this.estimatedAltitudeSeries); stage.setScene(new Scene(chart)); }
public static Series<String, Number> getSourceData(String monthName) { XYChart.Series<String, Number> source = new XYChart.Series<>(); String allSource[] = new ComboboxList().getSourceListForDashboard(); for (String sourceName : allSource) { if (!sourceName.equals("All")) { String sourceShortName = getAbbreviateName(sourceName); double amount = longToDouble(new Source().getAmountBySourceFromGM(monthName, sourceName)); source.getData().add(new XYChart.Data<>(sourceShortName, amount)); } } return source; }
private void getMoneyChart() { gmXaxis.setLabel("Sources Name"); gmYaxis.setLabel("Amount"); chartGetMoney.setTitle("Get Money( " + cmboGetMoneyMonthList.getValue()+" )"); Series<String, Number> gmChartData = GetMoneyChart.getSourceData(cmboGetMoneyMonthList.getValue()); chartGetMoney.getData().add(gmChartData); }
private void expenseChart() { exXaxis.setLabel("Sectors Name"); exYaxis.setLabel("Amount"); chartExpense.setTitle("Expense( " + cmboExpenseMonthList.getValue()+" )"); Series<String, Number> exChartData = ExpenseChart.getExpenseData(cmboExpenseMonthList.getValue()); chartExpense.getData().add(exChartData); }
private List<Series<Number, Number>> buildLabeledSeries() { List<XYChart.Series<Number, Number>> realSeries = new ArrayList<>(); Attribute irisClasses = data.attribute(2); data.stream().collect(Collectors.groupingBy(d -> { int i = (int) d.value(2); return irisClasses.value(i); })).forEach((e, instances) -> { XYChart.Series<Number, Number> series = new XYChart.Series<>(); series.setName(e); instances.stream().map(this::instancetoChartData).forEach(series.getData()::add); realSeries.add(series); }); return realSeries; }
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; }
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; }
@SuppressWarnings({ "unchecked", "rawtypes" }) private ObservableList<XYChart.Series<String, Double>> getChartData() { double aValue = 0; lperson= new Label(); ObservableList<XYChart.Series<String, Double>> answer = FXCollections.observableArrayList(); Series<String, Double> aSeries = new Series<String, Double>(); aSeries.setName("dates"); String qcount= "SELECT date, COUNT(date) FROM gateentry where type='"+lp+"' GROUP BY date"; DBConnect.connect(); try { ResultSet rec = DBConnect.stmt.executeQuery(qcount); while(rec.next()) { String date = rec.getString("date"); int count= rec.getInt("COUNT(date)"); aSeries.getData().add(new XYChart.Data(date, count)); aValue = aValue + Math.random() - .5; } } catch (SQLException e) { ErrorMessage.display("SQL Error", e.getMessage()+"\n error"); e.printStackTrace(); } answer.addAll(aSeries); return answer; }
@SuppressWarnings({ "unchecked", "rawtypes" }) private ObservableList<XYChart.Series<String, Double>> getChartData() { double aValue = 0; ObservableList<XYChart.Series<String, Double>> answer = FXCollections.observableArrayList(); Series<String, Double> aSeries = new Series<String, Double>(); aSeries.setName("dates"); String qcount= "SELECT date, COUNT(date) FROM gateentry GROUP BY date"; DBConnect.connect(); try { ResultSet rec = DBConnect.stmt.executeQuery(qcount); while(rec.next()) { String date = rec.getString("date"); int count= rec.getInt("COUNT(date)"); aSeries.getData().add(new XYChart.Data(date, count)); aValue = aValue + Math.random() - .5; } } catch (SQLException e) { ErrorMessage.display("SQL Error", e.getMessage()+"\n error"); e.printStackTrace(); } answer.addAll(aSeries); return answer; }
@SuppressWarnings({ "unchecked", "rawtypes" }) private ObservableList<XYChart.Series<String, Double>> getChartData() { double aValue = 0; ObservableList<XYChart.Series<String, Double>> answer = FXCollections.observableArrayList(); Series<String, Double> aSeries = new Series<String, Double>(); aSeries.setName("dates"); String qcount= "SELECT date, COUNT(date) FROM officeentry GROUP BY date"; DBConnect.connect(); try { ResultSet rec = DBConnect.stmt.executeQuery(qcount); while(rec.next()) { String date = rec.getString("date"); int count= rec.getInt("COUNT(date)"); aSeries.getData().add(new XYChart.Data(date, count)); aValue = aValue + Math.random() - .5; } } catch (SQLException e) { ErrorMessage.display("SQL Error", e.getMessage()+"\n error"); e.printStackTrace(); } answer.addAll(aSeries); return answer; }
static <X, Y> ObservableList<XYChart.Series<X, Y>> deepCopySeries(final Collection<XYChart.Series<X, Y>> data) { final ObservableList<XYChart.Series<X, Y>> backup = FXCollections.observableArrayList(); for (final Series<X, Y> s : data) { backup.add(deepCopySeries(s)); } return backup; }
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"); } }
private void doZoom(final boolean x, String s1, String s2) { if (s1 == null && s2 == null) { return; } if (s1 == null) { s1 = s2; } if (s2 == null) { s2 = s1; } final Iterator<XYChart.Series<X, Y>> it = chart.getData().iterator(); while (it.hasNext()) { final XYChart.Series<X, Y> s = it.next(); final List<?> values; if (x) { values = extractXValues(s.getData()); } else { values = extractYValues(s.getData()); } final int index1 = values.indexOf(s1); final int index2 = values.indexOf(s2); final int lower = Math.min(index1, index2); final int upper = Math.max(index1, index2); final Iterator<Data<X, Y>> it2 = s.getData().iterator(); while (it2.hasNext()) { final Data<X, Y> d = it2.next(); final Object value; if (x) { value = d.getXValue(); } else { value = d.getYValue(); } final int index = values.indexOf(value); if (index != -1 && (index < lower || index > upper)) { it2.remove(); } } } }