當前位置: 首頁>>代碼示例>>Java>>正文


Java XYChart類代碼示例

本文整理匯總了Java中javafx.scene.chart.XYChart的典型用法代碼示例。如果您正苦於以下問題:Java XYChart類的具體用法?Java XYChart怎麽用?Java XYChart使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


XYChart類屬於javafx.scene.chart包,在下文中一共展示了XYChart類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: init

import javafx.scene.chart.XYChart; //導入依賴的package包/類
private void init(Stage primaryStage) {
    Group root = new Group();
    primaryStage.setScene(new Scene(root));
    NumberAxis xAxis = new NumberAxis("Values for X-Axis", 0, 3, 1);
    NumberAxis yAxis = new NumberAxis("Values for Y-Axis", 0, 3, 1);
    ObservableList<XYChart.Series<Double,Double>> lineChartData = FXCollections.observableArrayList(
        new LineChart.Series<Double,Double>("Series 1", FXCollections.observableArrayList(
            new XYChart.Data<Double,Double>(0.0, 1.0),
            new XYChart.Data<Double,Double>(1.2, 1.4),
            new XYChart.Data<Double,Double>(2.2, 1.9),
            new XYChart.Data<Double,Double>(2.7, 2.3),
            new XYChart.Data<Double,Double>(2.9, 0.5)
        )),
        new LineChart.Series<Double,Double>("Series 2", FXCollections.observableArrayList(
            new XYChart.Data<Double,Double>(0.0, 1.6),
            new XYChart.Data<Double,Double>(0.8, 0.4),
            new XYChart.Data<Double,Double>(1.4, 2.9),
            new XYChart.Data<Double,Double>(2.1, 1.3),
            new XYChart.Data<Double,Double>(2.6, 0.9)
        ))
    );
    LineChart chart = new LineChart(xAxis, yAxis, lineChartData);
    root.getChildren().add(chart);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:25,代碼來源:ChartLine.java

示例2: createBarChart

import javafx.scene.chart.XYChart; //導入依賴的package包/類
private BarChart createBarChart() {
    CategoryAxis xAxis = new CategoryAxis();
    xAxis.setCategories(FXCollections.<String>observableArrayList(tableModel.getColumnNames()));
    xAxis.setLabel("Year");

    double tickUnit = tableModel.getTickUnit();

    NumberAxis yAxis = new NumberAxis();
    yAxis.setTickUnit(tickUnit);
    yAxis.setLabel("Units Sold");

    final BarChart chart = new BarChart(xAxis, yAxis, tableModel.getBarChartData());
    tableModel.addTableModelListener(new TableModelListener() {

        public void tableChanged(TableModelEvent e) {
            if (e.getType() == TableModelEvent.UPDATE) {
                final int row = e.getFirstRow();
                final int column = e.getColumn();
                final Object value = ((SampleTableModel) e.getSource()).getValueAt(row, column);

                Platform.runLater(new Runnable() {
                    public void run() {
                        XYChart.Series<String, Number> s = (XYChart.Series<String, Number>) chart.getData().get(row);
                        BarChart.Data data = s.getData().get(column);
                        data.setYValue(value);
                    }
                });
            }
        }
    });
    return chart;
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:33,代碼來源:SwingInterop.java

示例3: seriesRemoved

import javafx.scene.chart.XYChart; //導入依賴的package包/類
@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);
        }
    }
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:22,代碼來源:AdvCandleStickChartSample.java

示例4: getExpenseData

import javafx.scene.chart.XYChart; //導入依賴的package包/類
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;
}
 
開發者ID:krHasan,項目名稱:Money-Manager,代碼行數:20,代碼來源:ExpenseChart.java

示例5: createChart

import javafx.scene.chart.XYChart; //導入依賴的package包/類
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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:19,代碼來源:ChartAdvancedScatter.java

示例6: createChart

import javafx.scene.chart.XYChart; //導入依賴的package包/類
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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:23,代碼來源:ChartAdvancedArea.java

示例7: createChart

import javafx.scene.chart.XYChart; //導入依賴的package包/類
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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:25,代碼來源:ChartAudioArea.java

示例8: addDataItemNumStr

import javafx.scene.chart.XYChart; //導入依賴的package包/類
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)));
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:23,代碼來源:ChartActions.java

示例9: createChart

import javafx.scene.chart.XYChart; //導入依賴的package包/類
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;
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:21,代碼來源:AdvancedBubbleChartSample.java

示例10: deepCopySeriesData

import javafx.scene.chart.XYChart; //導入依賴的package包/類
static <X, Y> ObservableList<XYChart.Data<X, Y>> deepCopySeriesData(
        final Collection<? extends XYChart.Data<X, Y>> data) {
    final ObservableList<XYChart.Data<X, Y>> result = FXCollections.observableArrayList();
    for (final Data<X, Y> i : data) {
        result.add(new Data<>(i.getXValue(), i.getYValue()));
    }
    return result;
}
 
開發者ID:gransort,項目名稱:Java-oscilloscope-project,代碼行數:9,代碼來源:ZoomManager.java

示例11: addDataItemStrNum

import javafx.scene.chart.XYChart; //導入依賴的package包/類
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)));
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:23,代碼來源:ChartActions.java

示例12: createChart

import javafx.scene.chart.XYChart; //導入依賴的package包/類
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;
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:20,代碼來源:AdvancedLineChartSample.java

示例13: createChart

import javafx.scene.chart.XYChart; //導入依賴的package包/類
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;
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:21,代碼來源:AdvLineCategoryChartSample.java

示例14: LineChartSample

import javafx.scene.chart.XYChart; //導入依賴的package包/類
public LineChartSample() {
    NumberAxis xAxis = new NumberAxis("Values for X-Axis", 0, 3, 1);
    NumberAxis yAxis = new NumberAxis("Values for Y-Axis", 0, 3, 1);
    ObservableList<XYChart.Series<Double,Double>> lineChartData = FXCollections.observableArrayList(
        new LineChart.Series<Double,Double>("Series 1", FXCollections.observableArrayList(
            new XYChart.Data<Double,Double>(0.0, 1.0),
            new XYChart.Data<Double,Double>(1.2, 1.4),
            new XYChart.Data<Double,Double>(2.2, 1.9),
            new XYChart.Data<Double,Double>(2.7, 2.3),
            new XYChart.Data<Double,Double>(2.9, 0.5)
        )),
        new LineChart.Series<Double,Double>("Series 2", FXCollections.observableArrayList(
            new XYChart.Data<Double,Double>(0.0, 1.6),
            new XYChart.Data<Double,Double>(0.8, 0.4),
            new XYChart.Data<Double,Double>(1.4, 2.9),
            new XYChart.Data<Double,Double>(2.1, 1.3),
            new XYChart.Data<Double,Double>(2.6, 0.9)
        ))
    );
    LineChart chart = new LineChart(xAxis, yAxis, lineChartData);
    getChildren().add(chart);
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:23,代碼來源:LineChartSample.java

示例15: ScatterChartSample

import javafx.scene.chart.XYChart; //導入依賴的package包/類
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);
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:21,代碼來源:ScatterChartSample.java


注:本文中的javafx.scene.chart.XYChart類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。