Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Copyright (c) 2008, 2012 Oracle and/or its affiliates.
- * All rights reserved. Use is subject to license terms.
- *
- * This file is available and licensed under the following license:
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the distribution.
- * - Neither the name of Oracle Corporation nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
- package chartadvancedscatter;
- import java.util.HashMap;
- import java.util.Map;
- import javafx.application.Application;
- import javafx.geometry.Side;
- import javafx.scene.Group;
- import javafx.scene.Scene;
- import javafx.scene.chart.LineChart;
- import javafx.scene.chart.NumberAxis;
- import javafx.scene.chart.ScatterChart;
- import javafx.scene.chart.XYChart;
- import javafx.stage.Stage;
- /**
- * An advanced scatter chart with a variety of controls.
- *
- * @see javafx.scene.chart.ScatterChart
- * @see javafx.scene.chart.Chart
- * @see javafx.scene.chart.Axis
- * @see javafx.scene.chart.NumberAxis
- */
- public class ChartAdvancedScatter extends Application {
- private void init(Stage primaryStage) {
- Group root = new Group();
- primaryStage.setScene(new Scene(root));
- root.getChildren().add(createQuadraticPolynomialChart());
- }
- 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");
- // 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;
- }
- protected LineChart<Number, Number> createConstantLinearFunction()
- {
- final NumberAxis xAxis = new NumberAxis();
- xAxis.setSide(Side.TOP);
- final NumberAxis yAxis = new NumberAxis();
- yAxis.setSide(Side.RIGHT);
- final LineChart<Number,Number> sc = new LineChart<Number,Number>(xAxis,yAxis);
- // setup chart
- 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");
- HashMap<Number, Number> chartElements = Functions.LinearFunction(30);
- for(Map.Entry<Number, Number> chartElement : chartElements.entrySet())
- {
- series.getData().add(new XYChart.Data<Number, Number>(chartElement.getKey(), chartElement.getValue()));
- }
- sc.getData().add(series);
- return sc;
- }
- protected LineChart<Number, Number> createQuadraticFunctionChart()
- {
- final NumberAxis xAxis = new NumberAxis();
- xAxis.setSide(Side.TOP);
- final NumberAxis yAxis = new NumberAxis();
- yAxis.setSide(Side.RIGHT);
- final LineChart<Number,Number> sc = new LineChart<Number,Number>(xAxis,yAxis);
- // setup chart
- 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");
- HashMap<Number, Number> chartElements = Functions.QuadraticFunction(30);
- for(Map.Entry<Number, Number> chartElement : chartElements.entrySet())
- {
- series.getData().add(new XYChart.Data<Number, Number>(chartElement.getKey(), chartElement.getValue()));
- }
- sc.getData().add(series);
- return sc;
- }
- protected LineChart<Number, Number> createQuadraticPolynomialChart()
- {
- final NumberAxis xAxis = new NumberAxis();
- xAxis.setSide(Side.TOP);
- final NumberAxis yAxis = new NumberAxis();
- yAxis.setSide(Side.RIGHT);
- final LineChart<Number,Number> sc = new LineChart<Number,Number>(xAxis,yAxis);
- // setup chart
- 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");
- HashMap<Number, Number> chartElements = Functions.PolynomialFunction(30);
- for(Map.Entry<Number, Number> chartElement : chartElements.entrySet())
- {
- series.getData().add(new XYChart.Data<Number, Number>(chartElement.getKey(), chartElement.getValue()));
- }
- sc.getData().add(series);
- return sc;
- }
- @Override public void start(Stage primaryStage) throws Exception {
- init(primaryStage);
- primaryStage.show();
- }
- /**
- * The main() method is ignored in correctly deployed JavaFX
- * application. main() serves only as fallback in case the
- * application can not be launched through deployment artifacts,
- * e.g., in IDEs with limited FX support. NetBeans ignores main().
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- launch(args);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement