javafx.scene.chart.XYChart.Data Java Examples

The following examples show how to use javafx.scene.chart.XYChart.Data. 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: OutOfSampleErrorPlotPluginView.java    From AILibs with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void update() {
	
	/* compute data to add */
	List<Integer> observedTimestamps = getModel().getTimestamps();
	List<List<Double>> performances = getModel().getPerformances();
	List<Data<Number, Number>> believedErrors = new ArrayList<>();
	List<Data<Number, Number>> outOfSampleErrors = new ArrayList<>();
	for (; nextIndexToDisplay < observedTimestamps.size(); nextIndexToDisplay++) {
		int timestamp = observedTimestamps.get(nextIndexToDisplay) / 100;
		believedErrors.add(new Data<>(timestamp, performances.get(nextIndexToDisplay).get(0)));
		outOfSampleErrors.add(new Data<>(timestamp, performances.get(nextIndexToDisplay).get(1)));
	}
	logger.info("Adding {} values to chart.", believedErrors.size());
	Platform.runLater(() -> {
		believedErrorSeries.getData().addAll(believedErrors);
		outOfSampleErrorSeries.getData().addAll(outOfSampleErrors);
	});

}
 
Example #2
Source File: HistogramAccumulator.java    From HdrHistogramVisualizer with Apache License 2.0 6 votes vote down vote up
@Override
List<Data<Number, Number>> getPercentileData(int percentileOutputTicksPerHalf,
                                             DoubleUnaryOperator xConversion,
                                             DoubleUnaryOperator yConversion) {
    PercentileIterator percentileIterator = new PercentileIterator(
            accumulatedHistogram,
            percentileOutputTicksPerHalf);

    List<Data<Number, Number>> percentileData = new ArrayList<>(512);

    while (percentileIterator.hasNext()) {
        HistogramIterationValue value = percentileIterator.next();

        final double x = xConversion.applyAsDouble(value.getPercentileLevelIteratedTo());
        final double y = yConversion.applyAsDouble(value.getValueIteratedTo());

        if (Double.isInfinite(x))
            break;

        percentileData.add(new Data<>(x, y));
    }

    return percentileData;
}
 
Example #3
Source File: HistogramAccumulator.java    From HdrHistogramVisualizer with Apache License 2.0 6 votes vote down vote up
@Override
List<Data<Number, Number>> getPercentileData(int percentileOutputTicksPerHalf,
                                             DoubleUnaryOperator xConversion,
                                             DoubleUnaryOperator yConversion) {

    DoublePercentileIterator percentileIterator = new DoublePercentileIterator(
            accumulatedHistogram,
            percentileOutputTicksPerHalf);

    List<Data<Number, Number>> percentileData = new ArrayList<>(512);

    while (percentileIterator.hasNext()) {
        DoubleHistogramIterationValue value = percentileIterator.next();

        final double x = xConversion.applyAsDouble(value.getPercentileLevelIteratedTo());
        final double y = yConversion.applyAsDouble(value.getValueIteratedTo());

        if (Double.isInfinite(x))
            break;

        percentileData.add(new Data<>(x, y));
    }

    return percentileData;
}
 
Example #4
Source File: SolutionPerformanceTimelinePluginView.java    From AILibs with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void update() {

	/* compute data to add */
	List<Pair<Integer, Double>> events = this.getModel().getTimedPerformances();
	List<Data<Number, Number>> values = new ArrayList<>();
	for (; this.nextIndexToDisplay < events.size(); this.nextIndexToDisplay++) {
		Pair<Integer, Double> entry = events.get(this.nextIndexToDisplay);
		values.add(new Data<>(entry.getKey() / 1000.0, entry.getValue()));
	}
	this.logger.info("Adding {} values to chart.", values.size());
	Platform.runLater(() -> {
		this.performanceSeries.getData().addAll(values);
	});

}
 
Example #5
Source File: Clustering.java    From java-ml-projects with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #6
Source File: ChartActions.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public static void addDataItemNumStr(final XYChart<Number, String> chart) {
    if (chart.getData() == null) {
        chart.setData(FXCollections.<XYChart.Series<Number, String>>observableArrayList());
    }
    if (chart.getData().isEmpty()) {
        chart.getData().add(new XYChart.Series<Number, String>());
    }
    
    int sIndex = (int) (Math.random() * chart.getData().size());
    XYChart.Series<Number, String> series = chart.getData().get(sIndex);
    
    Set<String> existingYears = new HashSet<String>();
    for (Data<Number, String> data : series.getData()) {
        existingYears.add(data.getYValue());
    }
    
    int randomYear = 1900 + (int) (Math.round(12 * Math.random()) * 10);
    while (existingYears.contains(Integer.toString(randomYear))) {
        randomYear++;
    }
    series.getData().add(new XYChart.Data<Number, String>(10 + (Math.random() * 3800), Integer.toString(randomYear)));
}
 
Example #7
Source File: ChartActions.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public static void addDataItemNumStr(final XYChart<Number, String> chart) {
    if (chart.getData() == null) {
        chart.setData(FXCollections.<XYChart.Series<Number, String>>observableArrayList());
    }
    if (chart.getData().isEmpty()) {
        chart.getData().add(new XYChart.Series<Number, String>());
    }
    
    int sIndex = (int) (Math.random() * chart.getData().size());
    XYChart.Series<Number, String> series = chart.getData().get(sIndex);
    
    Set<String> existingYears = new HashSet<String>();
    for (Data<Number, String> data : series.getData()) {
        existingYears.add(data.getYValue());
    }
    
    int randomYear = 1900 + (int) (Math.round(12 * Math.random()) * 10);
    while (existingYears.contains(Integer.toString(randomYear))) {
        randomYear++;
    }
    series.getData().add(new XYChart.Data<Number, String>(10 + (Math.random() * 3800), Integer.toString(randomYear)));
}
 
Example #8
Source File: ChartActions.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public static void addDataItemStrNum(final XYChart<String, Number> chart) {
    if (chart.getData() == null) {
        chart.setData(FXCollections.<XYChart.Series<String, Number>>observableArrayList());
    }
    if (chart.getData().isEmpty()) {
        chart.getData().add(new XYChart.Series<String, Number>());
    }
    
    int sIndex = (int) (Math.random() * chart.getData().size());
    XYChart.Series<String, Number> series = chart.getData().get(sIndex);
    
    Set<String> existingYears = new HashSet<String>();
    for (Data<String, Number> data : series.getData()) {
        existingYears.add(data.getXValue());
    }
    
    int randomYear = 1900 + (int) (Math.round(12 * Math.random()) * 10);
    while (existingYears.contains(Integer.toString(randomYear))) {
        randomYear++;
    }
    series.getData().add(new XYChart.Data<String, Number>(Integer.toString(randomYear), 10 + (Math.random() * 3800)));
}
 
Example #9
Source File: ChartActions.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public static void addDataItemStrNum(final XYChart<String, Number> chart) {
    if (chart.getData() == null) {
        chart.setData(FXCollections.<XYChart.Series<String, Number>>observableArrayList());
    }
    if (chart.getData().isEmpty()) {
        chart.getData().add(new XYChart.Series<String, Number>());
    }
    
    int sIndex = (int) (Math.random() * chart.getData().size());
    XYChart.Series<String, Number> series = chart.getData().get(sIndex);
    
    Set<String> existingYears = new HashSet<String>();
    for (Data<String, Number> data : series.getData()) {
        existingYears.add(data.getXValue());
    }
    
    int randomYear = 1900 + (int) (Math.round(12 * Math.random()) * 10);
    while (existingYears.contains(Integer.toString(randomYear))) {
        randomYear++;
    }
    series.getData().add(new XYChart.Data<String, Number>(Integer.toString(randomYear), 10 + (Math.random() * 3800)));
}
 
Example #10
Source File: ChooseParkingSlotController.java    From SmartCity-ParkingManagement with Apache License 2.0 5 votes vote down vote up
@FXML
public void showRatingChartButtonClicked(ActionEvent event) throws Exception{
	Stage s = new Stage();
	s.setTitle("Price - Rating graph");
       final NumberAxis xAxis = new NumberAxis(), yAxis = new NumberAxis();
       xAxis.setLabel("Rating");
       yAxis.setLabel("Price");

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

       //populating the series with data
       for (Map.Entry<Double, Double> entry : data.entrySet()){
       	Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info("rating: "+ 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 #11
Source File: HistogramTag.java    From HdrHistogramVisualizer with Apache License 2.0 5 votes vote down vote up
public List<Data<Number, Number>> getIntervalData(int samples) {
    final int rawSize = intervalX.size();
    checkState(intervalY.size() == rawSize, "x/y sizes do not match");
    List<Data<Number, Number>> intervalData = new ArrayList<>((rawSize / samples) + 1);

    // Stride through raw data and store the maxima within a time interval
    for (int i = 0; i < rawSize; i += samples) {

        // Use lowest x value as time interval as that results in the same
        // behavior as if the histograms would have been recorded in
        // larger intervals from the beginning.
        double x = intervalX.get(i);
        double y = intervalY.get(i);

        // Search for highest y value as we are interested in the maxima
        // of each interval.
        for (int j = 1; j < samples && (i + j) < rawSize; j++) {
            double yNext = intervalY.get(i + j);
            if (yNext > y) {
                y = yNext;
            }
        }

        intervalData.add(new Data<Number, Number>(x, convertValueUnits(y)));
    }

    return intervalData;

}
 
Example #12
Source File: DyIOchannelWidget.java    From BowlerStudio with GNU General Public License v3.0 5 votes vote down vote up
public void updateValue(){
	
	if(getValue()!=null){
		int current = getValue();
		Data<Integer, Integer> newChart = new XYChart.Data<Integer, Integer>(
        		(int) (startTime-System.currentTimeMillis()),
        		current);
		Platform.runLater(()->chanValue.setText(Integer.toString(current)));
			if(!positionSlider.isValueChanging()){// only updae the slider position if the user is not sliding it
				Platform.runLater(()->{
					if(positionSlider==null)
						return;
					positionSlider.valueProperty().removeListener(imp);
					positionSlider.setValue(current);
					setLatestValue(current);
					setFireValue(false);
					positionSlider.valueProperty().addListener(imp);
				});
			}
			Platform.runLater(()->{
				if(series.getData().size()>10){// if you keep many more points in the graph it will lag the rendering realy badly
					series.getData().remove(0);
				}
				
				Platform.runLater(()->{
			        series.getData().add(newChart);
			        value=null;
		        });
	        });
	}
}
 
Example #13
Source File: DistanceGraph.java    From SmartCity-ParkingManagement with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void start(Stage s) throws Exception {
	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(dest);

       //populating the series with data
       for (Map.Entry<Double, Double> entry : data.entrySet()){
       	LOGGER.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 #14
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 #15
Source File: RattingGraph.java    From SmartCity-ParkingManagement with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void start(Stage s) throws Exception {
	s.setTitle("Price - Distance graph");
       final NumberAxis xAxis = new NumberAxis(), yAxis = new NumberAxis();
       xAxis.setLabel("Ratting");
       yAxis.setLabel("Price");

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

       //populating the series with data
       for (Map.Entry<Double, Double> entry : data.entrySet()){
       	LOGGER.info("ratting: "+ 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 #16
Source File: ScatterChartPane.java    From constellation with Apache License 2.0 5 votes vote down vote up
/**
 * Update the current selection on the ScatterChart within this
 * ScatterChartPane. This allows a primary selection (which will highlight
 * in red) as well as a secondary selection (which will highlight in
 * yellow).
 *
 * @param primarySelection the set of data objects representing the primary
 * selection.
 * @param secondarySelection the set of data objects representing the
 * secondary selection.
 */
protected void selectElementsOnChart(final Set<ScatterData> primarySelection, final Set<ScatterData> secondarySelection) {
    final DropShadow primarySelectionShadow = new DropShadow(BlurType.THREE_PASS_BOX, Color.RED, 20.0, 0.85, 0.0, 0.0);
    final DropShadow secondarySelectionShadow = new DropShadow(BlurType.THREE_PASS_BOX, Color.YELLOW, 20.0, 0.85, 0.0, 0.0);

    Platform.runLater(() -> {
        synchronized (currentData) {
            for (final ScatterData data : currentData) {
                if (secondarySelection != null && secondarySelection.contains(data)) {
                    data.getData().getNode().setEffect(secondarySelectionShadow);
                    continue;
                }

                if (primarySelection != null && primarySelection.contains(data)) {
                    data.getData().getNode().setEffect(primarySelectionShadow);
                    continue;
                }

                @SuppressWarnings("unchecked") // getData will return data of type number and number 
                Data<Number, Number> data2 = (Data<Number, Number>) data.getData();
                Node dataNode = data2.getNode();
                dataNode.setEffect(null);
            }
        }
    });

    if (primarySelection != null && !currentSelectedData.equals(primarySelection)) {
        currentSelectedData.clear();
        currentSelectedData.addAll(primarySelection);
    }
}
 
Example #17
Source File: ChartDataItem.java    From mokka7 with Eclipse Public License 1.0 5 votes vote down vote up
public void create(long time) {

        if (list.size() >= maxHistory.get()) {
            list.remove(0, list.size() - maxHistory.get());
        }
        value.set(readValue());
        list.add(new Data<Number, Number>(time, value.get()));
    }
 
Example #18
Source File: ChartDataItem.java    From mokka7 with Eclipse Public License 1.0 4 votes vote down vote up
public ObservableList<Data<Number, Number>> getData() {
    return list;
}
 
Example #19
Source File: Clustering.java    From java-ml-projects with Apache License 2.0 4 votes vote down vote up
private XYChart.Data<Number, Number> instancetoChartData(Instance i) {
	return new XYChart.Data<Number, Number>(i.value(0), i.value(1));
}
 
Example #20
Source File: HistogramTag.java    From HdrHistogramVisualizer with Apache License 2.0 4 votes vote down vote up
public List<Data<Number, Number>> getPercentileData(int percentileOutputTicksPerHalf) {
    return accumulator.getPercentileData(percentileOutputTicksPerHalf,
            HistogramTag::convertPercentileToX,
            this::convertValueUnits);
}
 
Example #21
Source File: HistogramAccumulator.java    From HdrHistogramVisualizer with Apache License 2.0 4 votes vote down vote up
abstract List<Data<Number, Number>> getPercentileData(
int percentileOutputTicksPerHalf,
DoubleUnaryOperator xConversion,
DoubleUnaryOperator yConversion);
 
Example #22
Source File: DashboardController.java    From OEE-Designer with MIT License 4 votes vote down vote up
@Override
public void onClickCategory(XYChart.Data<String, Number> item) {
	String lossCategory = item.getXValue();
	showParetoTab(lossCategory);
}
 
Example #23
Source File: DashboardController.java    From OEE-Designer with MIT License 4 votes vote down vote up
private void onClickLossCategory(Series<Number, String> series, XYChart.Data<Number, String> lossCategory) {
	showParetoTab(series.getName());
}