类javafx.scene.chart.LineChart源码实例Demo

下面列出了怎么用javafx.scene.chart.LineChart的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: quantumjava   文件: Main.java
public static Chart plotFunction(List<Function<Double, Double>> functions, Number xStart, Number xEnd) {
    int div = 500;
    double x0 = xStart.doubleValue();
    double x1 = xEnd.doubleValue();
    double step = 1./div* (x1-x0);
    Axis<Number> xAxis = new NumberAxis(x0, x1, .1* (x1-x0));
    Axis<Number> yAxis = new NumberAxis();
    ObservableList<XYChart.Series<Number, Number>> series = FXCollections.observableArrayList();
    LineChart<Number,Number> chart = new LineChart(xAxis, yAxis, series);
    chart.setCreateSymbols(false);
    for (Function<Double, Double> f: functions) {
        XYChart.Series<Number, Number> mainSeries = new XYChart.Series();
        series.add(mainSeries);
        ObservableList<XYChart.Data<Number, Number>> data = FXCollections.observableArrayList();
        mainSeries.setData(data);
        for (double x = x0; x < x1; x= x +step) {
            final Number y = f.apply(x);
            data.add(new XYChart.Data<>(x,y));
        }
    }
    return chart;

}
 
源代码2 项目: chart-fx   文件: MultipleAxesLineChart.java
public MultipleAxesLineChart(final LineChart<?, ?> baseChart, final Color lineColor, final Double strokeWidth) {
    if (strokeWidth != null) {
        this.strokeWidth = strokeWidth;
    }
    this.baseChart = baseChart;

    chartColorMap.put(baseChart, lineColor);

    styleBaseChart(baseChart);
    styleChartLine(baseChart, lineColor);
    setFixedAxisWidth(baseChart);

    setAlignment(Pos.CENTER_LEFT);

    backgroundCharts.addListener((final Observable observable) -> rebuildChart());

    detailsWindow = new AnchorPane();
    bindMouseEvents(baseChart, this.strokeWidth);

    rebuildChart();
}
 
源代码3 项目: chart-fx   文件: MultipleAxesLineChart.java
private Node resizeBackgroundChart(final LineChart<?, ?> lineChart) {
    final HBox hBox = new HBox(lineChart);
    hBox.setAlignment(Pos.CENTER_LEFT);
    hBox.prefHeightProperty().bind(heightProperty());
    hBox.prefWidthProperty().bind(widthProperty());
    hBox.setMouseTransparent(true);

    lineChart.minWidthProperty()
            .bind(widthProperty().subtract((yAxisWidth + yAxisSeparation) * backgroundCharts.size()));
    lineChart.prefWidthProperty()
            .bind(widthProperty().subtract((yAxisWidth + yAxisSeparation) * backgroundCharts.size()));
    lineChart.maxWidthProperty()
            .bind(widthProperty().subtract((yAxisWidth + yAxisSeparation) * backgroundCharts.size()));

    lineChart.translateXProperty().bind(baseChart.getYAxis().widthProperty());
    lineChart.getYAxis().setTranslateX((yAxisWidth + yAxisSeparation) * backgroundCharts.indexOf(lineChart));
    lineChart.getXAxis().tickLabelRotationProperty().bind(baseChart.getXAxis().tickLabelRotationProperty());
    return hBox;
}
 
源代码4 项目: chart-fx   文件: MultipleAxesLineChart.java
private void styleBackgroundChart(final LineChart<?, ?> lineChart, final Color lineColor) {
    styleChartLine(lineChart, lineColor);

    final Node chartContent = lineChart.lookup(".chart-content");
    if (chartContent != null) {
        final Node chartPlotBackground = chartContent.lookup(".chart-plot-background");
        if (chartPlotBackground != null) {
            chartPlotBackground.setStyle("-fx-background-color: transparent;");
        }
    }

    lineChart.setVerticalZeroLineVisible(false);
    lineChart.setHorizontalZeroLineVisible(false);
    lineChart.setVerticalGridLinesVisible(false);
    lineChart.setHorizontalGridLinesVisible(false);
    lineChart.setCreateSymbols(false);
}
 
源代码5 项目: OEE-Designer   文件: OpcDaTagValueChart.java
public LineChart<Number, Number> createChart() {

		tagValueChart.setId(chartId);
		tagValueChart.setCreateSymbols(true);
		tagValueChart.setAnimated(false);
		tagValueChart.setLegendVisible(false);

		xAxis.setLabel(xAxisLabel);
		xAxis.setForceZeroInRange(false);
		yAxis.setLabel(yAxisLabel);
		yAxis.setAutoRanging(true);

		valueDataSeries.setName(seriesName);
		tagValueChart.getData().add(valueDataSeries);

		reset(title);

		return tagValueChart;
	}
 
源代码6 项目: marathonv5   文件: AdvancedLineChartSample.java
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;
}
 
源代码7 项目: marathonv5   文件: AdvLineCategoryChartSample.java
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;
}
 
源代码8 项目: marathonv5   文件: LineChartSample.java
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);
}
 
源代码9 项目: marathonv5   文件: AdvancedLineChartSample.java
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;
}
 
源代码10 项目: marathonv5   文件: AdvLineCategoryChartSample.java
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;
}
 
源代码11 项目: marathonv5   文件: LineChartSample.java
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);
}
 
public void simpleIndexChart(Stage stage) {
    stage.setTitle("Index Chart");
    final LineChart<String, Number> lineChart
            = new LineChart<>(xAxis, yAxis);
    lineChart.setTitle("Belgium Population");
    yAxis.setLabel("Population");

    series.setName("Population");
    addDataItem(series, "1950", 8639369);
    addDataItem(series, "1960", 9118700);
    addDataItem(series, "1970", 9637800);
    addDataItem(series, "1980", 9846800);
    addDataItem(series, "1990", 9969310);
    addDataItem(series, "2000", 10263618);

    Scene scene = new Scene(lineChart, 800, 600);
    lineChart.getData().add(series);
    stage.setScene(scene);
    stage.show();
}
 
源代码13 项目: netbeans   文件: ChartLine.java
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);
}
 
源代码14 项目: zest-writer   文件: MenuController.java
private void displayIndex(Map<String, Double> resultIndex, String title, String header) {
    BaseDialog dialog = new BaseDialog(title, header);
    dialog.getDialogPane().setPrefSize(800, 600);
    dialog.getDialogPane().getButtonTypes().addAll(new ButtonType(Configuration.getBundle().getString("ui.actions.stats.close"), ButtonBar.ButtonData.CANCEL_CLOSE));

    // draw
    final CategoryAxis xAxis = new CategoryAxis();
    final NumberAxis yAxis = new NumberAxis();
    final LineChart<String,Number> lineChart = new LineChart<>(xAxis, yAxis);
    lineChart.setTitle(title);
    lineChart.setLegendVisible(false);

    xAxis.setLabel(Configuration.getBundle().getString("ui.actions.stats.xaxis"));
    yAxis.setLabel(Configuration.getBundle().getString("ui.actions.readable.yaxis"));

    XYChart.Series<String, Number> series = new XYChart.Series();
    for(Map.Entry<String, Double> st:resultIndex.entrySet()) {
        series.getData().add(new XYChart.Data(st.getKey(), st.getValue()));
    }
    lineChart.getData().addAll(series);
    dialog.getDialogPane().setContent(lineChart);
    dialog.setResizable(true);
    dialog.showAndWait();
}
 
源代码15 项目: spring-labs   文件: SinChartComponent.java
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);
  }
 
源代码16 项目: chart-fx   文件: JavaFXTestChart.java
public JavaFXTestChart() {

        xAxis.setLabel("x-axis (JavaFX Chart)");
        xAxis.setAutoRanging(false);
        yAxis.setAutoRanging(false);
        yAxis.setLowerBound(-1.1);
        yAxis.setUpperBound(+1.1);

        // Create a LineChart
        lineChart = new LineChart<Number, Number>(xAxis, yAxis) {
            // Override to remove symbols on each data point
            @Override
            protected void dataItemAdded(final Series<Number, Number> series, final int itemIndex,
                    final Data<Number, Number> item) {
            }
        };
        lineChart.setAnimated(false);
        lineChart.setHorizontalGridLinesVisible(true);
        lineChart.setVerticalGridLinesVisible(true);
        lineChart.setCreateSymbols(false);
        lineChart.getXAxis().setAnimated(false);
        lineChart.getYAxis().setAnimated(false);
        lineChart.setHorizontalZeroLineVisible(false);
        lineChart.getStylesheets()
                .add(RollingBufferLegacySample.class.getResource("RollingBufferLegacy.css").toExternalForm());
        series1.setName("test data [a.u.]");
        lineChart.getData().add(series1);
        lineChart.setLegendVisible(false);

        setNumberOfSamples(MAX_DATA_POINTS_1K);
        updateDataSet(); // NOPMD
    }
 
源代码17 项目: chart-fx   文件: MultipleAxesLineChart.java
public void addSeries(final XYChart.Series<Number, Number> series, final Color lineColor) {
    final NumberAxis yAxis = new NumberAxis();
    final NumberAxis xAxis = new NumberAxis();

    // style x-axis
    xAxis.setAutoRanging(false);
    xAxis.setVisible(false);
    xAxis.setOpacity(0.0); // somehow the upper setVisible does not work
    xAxis.lowerBoundProperty().bind(((NumberAxis) baseChart.getXAxis()).lowerBoundProperty());
    xAxis.upperBoundProperty().bind(((NumberAxis) baseChart.getXAxis()).upperBoundProperty());
    xAxis.tickUnitProperty().bind(((NumberAxis) baseChart.getXAxis()).tickUnitProperty());

    // style y-axis
    yAxis.setSide(Side.RIGHT);
    yAxis.setLabel(series.getName());

    // create chart
    final LineChart<Number, Number> lineChart = new LineChart<>(xAxis, yAxis);
    lineChart.setAnimated(false);
    lineChart.setLegendVisible(false);
    lineChart.getData().add(series);

    styleBackgroundChart(lineChart, lineColor);
    setFixedAxisWidth(lineChart);

    chartColorMap.put(lineChart, lineColor);
    backgroundCharts.add(lineChart);
}
 
源代码18 项目: chart-fx   文件: MultipleAxesLineChart.java
private void bindMouseEvents(final LineChart<?, ?> baseChart, final Double strokeWidth) {
    getChildren().add(detailsWindow);
    detailsWindow.prefHeightProperty().bind(heightProperty());
    detailsWindow.prefWidthProperty().bind(widthProperty());
    detailsWindow.setMouseTransparent(true);

    setOnMouseMoved(null);
    setMouseTransparent(false);

    final Axis<?> xAxis = baseChart.getXAxis();
    final Axis<?> yAxis = baseChart.getYAxis();

    final Line xLine = new Line();
    final Line yLine = new Line();
    yLine.setFill(Color.GRAY);
    xLine.setFill(Color.GRAY);
    yLine.setStrokeWidth(strokeWidth / 2);
    xLine.setStrokeWidth(strokeWidth / 2);
    xLine.setVisible(false);
    yLine.setVisible(false);

    final Node chartBackground = baseChart.lookup(".chart-plot-background");
    for (final Node n : chartBackground.getParent().getChildrenUnmodifiable()) {
        if ((n != chartBackground) && (n != xAxis) && (n != yAxis)) {
            n.setMouseTransparent(true);
        }
    }
}
 
源代码19 项目: chart-fx   文件: MultipleAxesLineChart.java
public Node getLegend() {
    final HBox hBox = new HBox();

    final CheckBox baseChartCheckBox = new CheckBox(baseChart.getYAxis().getLabel());
    baseChartCheckBox.setSelected(true);
    baseChartCheckBox
            .setStyle("-fx-text-fill: " + toRGBCode(chartColorMap.get(baseChart)) + "; -fx-font-weight: bold;");
    baseChartCheckBox.setDisable(true);
    baseChartCheckBox.getStyleClass().add("readonly-checkbox");
    baseChartCheckBox.setOnAction(event -> baseChartCheckBox.setSelected(true));
    hBox.getChildren().add(baseChartCheckBox);

    for (final LineChart<?, ?> lineChart : backgroundCharts) {
        final CheckBox checkBox = new CheckBox(lineChart.getYAxis().getLabel());
        checkBox.setStyle("-fx-text-fill: " + toRGBCode(chartColorMap.get(lineChart)) + "; -fx-font-weight: bold");
        checkBox.setSelected(true);
        checkBox.setOnAction(event -> {
            if (backgroundCharts.contains(lineChart)) {
                backgroundCharts.remove(lineChart);
            } else {
                backgroundCharts.add(lineChart);
            }
        });
        hBox.getChildren().add(checkBox);
    }

    hBox.setAlignment(Pos.CENTER);
    hBox.setSpacing(20);
    hBox.setStyle("-fx-padding: 0 10 20 10");

    return hBox;
}
 
源代码20 项目: chart-fx   文件: MultipleAxesLineChart.java
private void rebuildChart() {
    getChildren().clear();

    getChildren().add(resizeBaseChart(baseChart));
    for (final LineChart<?, ?> lineChart : backgroundCharts) {
        getChildren().add(resizeBackgroundChart(lineChart));
    }
    getChildren().add(detailsWindow);
}
 
源代码21 项目: chart-fx   文件: MultipleAxesLineChart.java
private Node resizeBaseChart(final LineChart<?, ?> lineChart) {
    final HBox hBox = new HBox(lineChart);
    hBox.setAlignment(Pos.CENTER_LEFT);
    hBox.prefHeightProperty().bind(heightProperty());
    hBox.prefWidthProperty().bind(widthProperty());

    lineChart.minWidthProperty()
            .bind(widthProperty().subtract((yAxisWidth + yAxisSeparation) * backgroundCharts.size()));
    lineChart.prefWidthProperty()
            .bind(widthProperty().subtract((yAxisWidth + yAxisSeparation) * backgroundCharts.size()));
    lineChart.maxWidthProperty()
            .bind(widthProperty().subtract((yAxisWidth + yAxisSeparation) * backgroundCharts.size()));

    return lineChart;
}
 
源代码22 项目: chart-fx   文件: MultipleAxesLineChart.java
private void styleBaseChart(final LineChart<?, ?> baseChart) {
    baseChart.setCreateSymbols(false);
    baseChart.setLegendVisible(false);
    baseChart.getXAxis().setAutoRanging(false);
    baseChart.getXAxis().setAnimated(false);
    baseChart.getYAxis().setAnimated(false);
}
 
源代码23 项目: OEE-Designer   文件: ParetoChartController.java
private LineChart<String, Number> createLineChart(String categoryLabel) {
	// X-Axis category (not shown)
	CategoryAxis xAxis = new CategoryAxis();
	xAxis.setLabel(categoryLabel);
	xAxis.setOpacity(0);

	// Y-Axis (%)
	NumberAxis yAxis = new NumberAxis(0, 100, 10);
	yAxis.setLabel(DesignerLocalizer.instance().getLangString("cum.percent"));
	yAxis.setSide(Side.RIGHT);
	yAxis.setAutoRanging(false);
	yAxis.setUpperBound(100.0d);
	yAxis.setLowerBound(0.0d);

	// create the line chart
	LineChart<String, Number> chLineChart = new LineChart<>(xAxis, yAxis);
	chLineChart.setTitle(chartTitle);
	chLineChart.setLegendVisible(false);
	chLineChart.setAnimated(false);
	chLineChart.setCreateSymbols(true);
	chLineChart.getData().add(lineChartSeries);

	// plot the points
	double total = totalCount.doubleValue();
	Float cumulative = new Float(0f);

	for (ParetoItem paretoItem : this.paretoItems) {
		cumulative += new Float(paretoItem.getValue().floatValue() / total * 100.0f);
		XYChart.Data<String, Number> point = new XYChart.Data<>(paretoItem.getCategory(), cumulative);
		lineChartSeries.getData().add(point);
	}

	return chLineChart;
}
 
源代码24 项目: DevToolBox   文件: ChartUtil.java
public static void changeChart(LineChart chart, Date now, Double dt, String name) {
    ObservableList<XYChart.Series> data = chart.getData();
    XYChart.Series xys = null;
    if (data.isEmpty()) {
        xys = getSeries(chart, dt, name);
        data.add(xys);
        addClickListener(chart);
    } else {
        boolean exits = false;
        for (XYChart.Series series : data) {
            if (name.equals(series.getName())) {
                exits = true;
                xys = series;
                break;
            }
        }
        if (!exits) {
            xys = getSeries(chart, dt, name);
            data.add(xys);
            addClickListener(chart);
        }
        NumberAxis na = (NumberAxis) chart.getYAxis();
        na.setUpperBound(Math.max(na.getUpperBound(), dt));
    }
    XYChart.Data xdata = new XYChart.Data<>(DATE_FORMAT.format(now), dt);
    xdata.setNode(new HoveredThresholdNode(dt, dt));
    xdata.getNode().setVisible(CACHE.get(name) == null ? true : CACHE.get(name));
    xys.getData().add(xdata);
    if (xys.getData().size() > 9) {
        xys.getData().remove(0);
    }
}
 
源代码25 项目: DevToolBox   文件: ChartUtil.java
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;
}
 
源代码26 项目: DevToolBox   文件: ChartUtil.java
private static void addClickListener(LineChart chart) {
    for (Node n : chart.getChildrenUnmodifiable()) {
        if (n instanceof Legend) {
            Legend l = (Legend) n;
            for (Legend.LegendItem li : l.getItems()) {
                for (Iterator it = chart.getData().iterator(); it.hasNext();) {
                    XYChart.Series<Number, Number> s = (XYChart.Series<Number, Number>) it.next();
                    if (s.getName().equals(li.getText())) {
                        li.getSymbol().setCursor(Cursor.HAND); // Hint user that legend symbol is clickable
                        if (li.getSymbol().getOnMouseClicked() == null) {
                            li.getSymbol().setOnMouseClicked(me -> {
                                if (me.getButton() == MouseButton.PRIMARY) {
                                    s.getNode().setVisible(!s.getNode().isVisible()); // Toggle visibility of line
                                    CACHE.put(s.getName(), s.getNode().isVisible());
                                    for (XYChart.Data<Number, Number> d : s.getData()) {
                                        if (d.getNode() != null) {
                                            d.getNode().setVisible(s.getNode().isVisible()); // Toggle visibility of every node in the series
                                        }
                                    }
                                    for (Iterator it2 = chart.getData().iterator(); it2.hasNext();) {
                                        XYChart.Series<Number, Number> s2 = (XYChart.Series<Number, Number>) it2.next();
                                        if (!s.equals(s2)) {
                                            for (XYChart.Data<Number, Number> d2 : s2.getData()) {
                                                if (!d2.getNode().isVisible()) {
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                }
                            });
                            break;
                        }
                    }
                }
            }
        }
    }
}
 
源代码27 项目: marathonv5   文件: AdvancedStockLineChartSample.java
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;
}
 
源代码28 项目: marathonv5   文件: AdvancedStockLineChartSample.java
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;
}
 
源代码29 项目: netbeans   文件: ChartAdvancedStockLine.java
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;
}
 
源代码30 项目: AILibs   文件: OutOfSampleErrorPlotPluginView.java
public OutOfSampleErrorPlotPluginView(OutOfSampleErrorPlotPluginModel model) {
	super(model, new LineChart<>(new NumberAxis(), new NumberAxis()));
	getNode().getXAxis().setLabel("elapsed time (s)");
	getNode().setTitle(getTitle());
	believedErrorSeries = new Series<>();
	believedErrorSeries.setName("Believed (internal) Error");
	outOfSampleErrorSeries = new Series<>();
	outOfSampleErrorSeries.setName("Out-of-Sample Error");
	getNode().getData().add(believedErrorSeries);
	getNode().getData().add(outOfSampleErrorSeries);
}
 
 类所在包
 同包方法