javafx.scene.chart.XYChart Java Examples

The following examples show how to use javafx.scene.chart.XYChart. 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: 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 #2
Source File: WordFrequencyApp.java    From FXTutorials with MIT License 6 votes vote down vote up
private Parent createContent() {
    StackPane root = new StackPane();
    root.setPrefSize(800, 600);

    BarChart<String, Number> chart = new BarChart<>(new CategoryAxis(), new NumberAxis());

    XYChart.Series<String, Number> series = new XYChart.Series<>();

    extractor.extract()
            .stream()
            .sorted((e1, e2) -> e2.getFrequency() - e1.getFrequency())
            .limit(10)
            .forEach(entry -> {
                series.getData().add(new XYChart.Data<>(entry.getWord(), entry.getFrequency()));
            });

    chart.getData().add(series);

    root.getChildren().add(chart);

    return root;
}
 
Example #3
Source File: AxisInlierUtils.java    From bisq with GNU Affero General Public License v3.0 6 votes vote down vote up
public static ListChangeListener<XYChart.Data<Number, Number>> getListenerThatZoomsToInliers(
        NumberAxis axis,
        int maxNumberOfTicks,
        double percentToTrim,
        double howManyStdDevsConstituteOutlier
) {
    return change -> {
        boolean axisHasBeenInitialized = axis != null;
        if (axisHasBeenInitialized) {
            zoomToInliers(
                    axis,
                    change.getList(),
                    maxNumberOfTicks,
                    percentToTrim,
                    howManyStdDevsConstituteOutlier
            );
        }
    };
}
 
Example #4
Source File: VelGraphController.java    From Motion_Profile_Generator with MIT License 6 votes vote down vote up
/**
 * Builds a series from the given trajectory that is ready to display on a LineChart.
 * @param segments Partial path to build a series for.
 * @return The created series to display.
 */
private static XYChart.Series<Double, Double> buildSeries( Path.Segment[] segments )
{
    XYChart.Series<Double, Double> series = new XYChart.Series<>();

    if( segments != null )
    {
        int i = 0;
        for( Path.Segment seg : segments )
        {
            // Holds x, y data for a single entry in the series.
            XYChart.Data<Double, Double> data = new XYChart.Data<>();

            // Set the x, y data.
            data.setXValue( seg.dt * i );
            data.setYValue( seg.velocity );

            // Add the data to the series.
            series.getData().add( data );

            i++;
        }
    }

    return series;
}
 
Example #5
Source File: CandleStickChart.java    From bisq with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected void dataItemAdded(XYChart.Series<Number, Number> series, int itemIndex, XYChart.Data<Number, Number> item) {
    Node candle = createCandle(getData().indexOf(series), item, itemIndex);
    getPlotChildren().remove(candle);

    if (shouldAnimate()) {
        candle.setOpacity(0);
        getPlotChildren().add(candle);
        // fade in new candle
        FadeTransition ft = new FadeTransition(Duration.millis(500), candle);
        ft.setToValue(1);
        ft.play();
    } else {
        getPlotChildren().add(candle);
    }
    // always draw average line on top

    if (series.getNode() instanceof Path) {
        Path seriesPath = (Path) series.getNode();
        seriesPath.toFront();
    }
}
 
Example #6
Source File: BsqDashboardView.java    From bisq with GNU Affero General Public License v3.0 6 votes vote down vote up
private void updateBsqPriceData() {
    seriesBSQPrice.getData().clear();

    Map<LocalDate, List<TradeStatistics2>> bsqPriceByDate = tradeStatisticsManager.getObservableTradeStatisticsSet().stream()
            .filter(e -> e.getCurrencyCode().equals("BSQ"))
            .sorted(Comparator.comparing(TradeStatistics2::getTradeDate))
            .collect(Collectors.groupingBy(item -> new java.sql.Date(item.getTradeDate().getTime()).toLocalDate()
                    .with(ADJUSTERS.get(DAY))));

    List<XYChart.Data<Number, Number>> updatedBSQPrice = bsqPriceByDate.keySet().stream()
            .map(e -> {
                ZonedDateTime zonedDateTime = e.atStartOfDay(ZoneId.systemDefault());
                return new XYChart.Data<Number, Number>(zonedDateTime.toInstant().getEpochSecond(), bsqPriceByDate.get(e).stream()
                        .map(TradeStatistics2::getTradePrice)
                        .mapToDouble(Price::getValue)
                        .average()
                        .orElse(Double.NaN)
                );
            })
            .collect(Collectors.toList());

    seriesBSQPrice.getData().setAll(updatedBSQPrice);
}
 
Example #7
Source File: AdvancedScatterChartSample.java    From marathonv5 with Apache License 2.0 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 #8
Source File: AdvLineCategoryChartSample.java    From marathonv5 with Apache License 2.0 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 #9
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 #10
Source File: ScatterChartSample.java    From marathonv5 with Apache License 2.0 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 #11
Source File: ChartAdvancedScatter.java    From netbeans with Apache License 2.0 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 #12
Source File: SupplyView.java    From bisq with GNU Affero General Public License v3.0 6 votes vote down vote up
private void initializeSeries() {
    // We can use the same labels for daily and monthly series
    var issuedLabel = Res.get("dao.factsAndFigures.supply.issued");
    var burntLabel = Res.get("dao.factsAndFigures.supply.burnt");

    seriesBSQIssuedMonthly = new XYChart.Series<>();
    seriesBSQIssuedMonthly.setName(issuedLabel);

    // Because Series cannot be reused in multiple charts, we create a
    // "second" Series and populate it at the same time as the original.
    // Some other solutions: https://stackoverflow.com/questions/49770442
    seriesBSQIssuedMonthly2 = new XYChart.Series<>();
    seriesBSQIssuedMonthly2.setName(issuedLabel);

    seriesBSQBurntMonthly = new XYChart.Series<>();
    seriesBSQBurntMonthly.setName(burntLabel);

    seriesBSQBurntDaily = new XYChart.Series<>();
    seriesBSQBurntDaily.setName(burntLabel);

    seriesBSQBurntDailyMA = new XYChart.Series<>();
    var burntMALabel = Res.get("dao.factsAndFigures.supply.burntMovingAverage");
    seriesBSQBurntDailyMA.setName(burntMALabel);
}
 
Example #13
Source File: VolumeChart.java    From bisq with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected void seriesRemoved(XYChart.Series<Number, Number> series) {
    for (XYChart.Data<Number, Number> d : series.getData()) {
        final Node volumeBar = d.getNode();
        if (shouldAnimate()) {
            FadeTransition ft = new FadeTransition(Duration.millis(500), volumeBar);
            ft.setToValue(0);
            ft.setOnFinished((ActionEvent actionEvent) -> getPlotChildren().remove(volumeBar));
            ft.play();
        } else {
            getPlotChildren().remove(volumeBar);
        }
    }
    if (shouldAnimate()) {
        new Timeline(new KeyFrame(Duration.millis(500), event -> removeSeriesFromDisplay(series))).play();
    } else {
        removeSeriesFromDisplay(series);
    }
}
 
Example #14
Source File: CurveFittedAreaChartSample.java    From marathonv5 with Apache License 2.0 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 #15
Source File: ScatterChartSample.java    From marathonv5 with Apache License 2.0 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 #16
Source File: AdvAreaAudioChartSample.java    From marathonv5 with Apache License 2.0 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 #17
Source File: SinChartComponent.java    From spring-labs with Apache License 2.0 6 votes vote down vote up
public SinChartComponent() {

    NumberAxis xAxis = new NumberAxis();
    xAxis.setLabel("x");

    NumberAxis yAxis = new NumberAxis();
    yAxis.setLabel("y");

    XYChart.Series<Number, Number> series = new XYChart.Series<>();
    series.setName("Sine");

    ObservableList<XYChart.Data<Number, Number>> data = series.getData();

    for (double x = -Math.PI; x < Math.PI; x += 0.5) {
      data.add(new XYChart.Data<Number, Number>(x, 10 * Math.sin(x)));
    }

    LineChart<Number, Number> lineChart = new LineChart<Number, Number>(xAxis, yAxis);
    lineChart.setTitle("Sine function");
    lineChart.getData().add(series);

    getChildren().add(lineChart);
  }
 
Example #18
Source File: ImageBarChartSample.java    From marathonv5 with Apache License 2.0 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 #19
Source File: AdvCandleStickChartSample.java    From marathonv5 with Apache License 2.0 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
Source File: PosGraphController.java    From Motion_Profile_Generator with MIT License 6 votes vote down vote up
/**
 * Builds a series from the given trajectory that is ready to display on a LineChart.
 * @param segments Collection of Segments to build a series for.
 * @return The created series to display.
 */
private static XYChart.Series<Double, Double> buildSegmentsSeries( Path.Segment[] segments )
{
    if( ( null == segments     )
     || ( 0 == segments.length ) )
    {
        return null;
    }

    XYChart.Series<Double, Double> series = new XYChart.Series<>();

    for( Path.Segment segment : segments )
    {
        // Holds x, y data for a single entry in the series.
        XYChart.Data<Double, Double> data = new XYChart.Data<>();

        // Set the x, y data.
        data.setXValue( segment.x );
        data.setYValue( segment.y );

        // Add the data to the series.
        series.getData().add( data );
    }

    return series;
}
 
Example #21
Source File: SmoothedChart.java    From tilesfx with Apache License 2.0 5 votes vote down vote up
public void setSymbolFill(final Series<X, Y> SERIES, final Background SYMBOL_BACKGROUND) {
    if (!getData().contains(SERIES)) { return; }
    for (XYChart.Data<X, Y> data : SERIES.getData()) {
        StackPane stackPane = (StackPane) data.getNode();
        if (null == stackPane) { continue; }
        stackPane.setBackground(SYMBOL_BACKGROUND);
    }
}
 
Example #22
Source File: ChooseParkingSlotController.java    From SmartCity-ParkingManagement with Apache License 2.0 5 votes vote down vote up
@FXML
public void showDistanceChartButtonClicked(ActionEvent event) throws Exception{
	
	 Stage s = new Stage();
        //Fill stage with content
		s.setTitle("Price - Distance graph");
        final NumberAxis xAxis = new NumberAxis(), yAxis = new NumberAxis();
        xAxis.setLabel("Distance");
        yAxis.setLabel("Price");

        //creating the chart
        final LineChart<Number,Number> lineChart = new LineChart<Number,Number>(xAxis,yAxis);
                
        lineChart.setTitle("Price - Distance");
        
        //defining a series
        XYChart.Series<Number, Number> series = new XYChart.Series<Number, Number>();
        series.setName("Price - Distance");
        
        //get data to present
        Graph g = new Graph();
        Map<Double, Double> data = g.CreatePriceDistanceData(getSelectedDestination());

        //populating the series with data
        for (Map.Entry<Double, Double> entry : data.entrySet()){
        	Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info("distance: "+ entry.getKey() + " price: " + entry.getValue());
        	series.getData().add(new Data<Number, Number>(entry.getKey(), entry.getValue()));
        }
	        
        Scene scene  = new Scene(lineChart,800,600);
        lineChart.getData().addAll(series);
       
        s.setScene(scene);
        s.show();
}
 
Example #23
Source File: CurveFittedAreaChartSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
/**
 * @inheritDoc
 */
@Override
protected void layoutPlotChildren() {
    super.layoutPlotChildren();
    for (int seriesIndex = 0; seriesIndex < getDataSize(); seriesIndex++) {
        final XYChart.Series<Number, Number> series = getData().get(seriesIndex);
        final Path seriesLine = (Path) ((Group) series.getNode()).getChildren().get(1);
        final Path fillPath = (Path) ((Group) series.getNode()).getChildren().get(0);
        smooth(seriesLine.getElements(), fillPath.getElements());
    }
}
 
Example #24
Source File: VolumeChart.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void dataItemAdded(XYChart.Series<Number, Number> series, int itemIndex, XYChart.Data<Number, Number> item) {
    Node volumeBar = createCandle(getData().indexOf(series), item, itemIndex);
    getPlotChildren().remove(volumeBar);

    if (shouldAnimate()) {
        volumeBar.setOpacity(0);
        getPlotChildren().add(volumeBar);
        FadeTransition ft = new FadeTransition(Duration.millis(500), volumeBar);
        ft.setToValue(1);
        ft.play();
    } else {
        getPlotChildren().add(volumeBar);
    }
}
 
Example #25
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 #26
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 #27
Source File: CPUUtilizationChartController.java    From trex-stateless-gui with Apache License 2.0 5 votes vote down vote up
private void setSeriesColor(final XYChart.Series<?, ?> series, final String color) {
    series.nodeProperty().addListener((ObservableValue<? extends Node> observable, Node oldValue, Node newValue) -> {
        if (oldValue == null && newValue != null) {
            series.getNode().setStyle(String.format("-fx-stroke: %s; -fx-stroke-line-join: round;", color));
        }
    });
}
 
Example #28
Source File: EpidemicReportsChartController.java    From MyBox with Apache License 2.0 5 votes vote down vote up
protected void drawValueBarsVertical(List<EpidemicReport> timeReports) {
    if (valuesNames.size() != 1 || timeReports == null || timeReports.isEmpty()) {
        return;
    }
    String valueName = orderNames.get(0);
    LabeledBarChart barChart = addVerticalBarChart();

    Map<String, String> palette = new HashMap();
    for (int i = 0; i < timeReports.size(); i++) {
        EpidemicReport report = timeReports.get(i);
        String location = report.getLocationFullName();
        String label = (multipleDatasets ? report.getDataSet() + " - " : "") + location;

        Number value = report.value(valueName);
        if (value == null) {
            continue;
        }
        double coordinateValue = FxmlControl.coordinateValue(chartCoordinate, value.doubleValue());
        XYChart.Series series = new XYChart.Series();
        series.setName(label);
        palette.put(label, settingsController.locationColors.get(location));
        XYChart.Data item = new XYChart.Data(label, coordinateValue);
        series.getData().add(item);
        barChart.getData().add(series);
        if (labelType == LabelType.Pop) {
            FxmlControl.setTooltip(item.getNode(), label + " " + value);
        }
    }
    FxmlControl.setBarChartColors(barChart, palette, legendSide != null);
}
 
Example #29
Source File: ChartUtil.java    From DevToolBox with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static XYChart.Series getSeries(LineChart chart, Double dt, String name) {
    NumberAxis na = (NumberAxis) chart.getYAxis();
    na.setAutoRanging(true);
    na.setForceZeroInRange(false);
    XYChart.Series s = new XYChart.Series();
    s.setName(name);
    return s;
}
 
Example #30
Source File: SmoothedChart.java    From OEE-Designer with MIT License 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); }
}