Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.80 KB | None | 0 0
  1. /*
  2.  * Copyright (c) 2008, 2012 Oracle and/or its affiliates.
  3.  * All rights reserved. Use is subject to license terms.
  4.  *
  5.  * This file is available and licensed under the following license:
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  *
  11.  *  - Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  *  - Redistributions in binary form must reproduce the above copyright
  14.  *    notice, this list of conditions and the following disclaimer in
  15.  *    the documentation and/or other materials provided with the distribution.
  16.  *  - Neither the name of Oracle Corporation nor the names of its
  17.  *    contributors may be used to endorse or promote products derived
  18.  *    from this software without specific prior written permission.
  19.  *
  20.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23.  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24.  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31.  */
  32. package chartadvancedscatter;
  33.  
  34. import java.util.HashMap;
  35. import java.util.Map;
  36. import javafx.application.Application;
  37. import javafx.geometry.Side;
  38. import javafx.scene.Group;
  39. import javafx.scene.Scene;
  40. import javafx.scene.chart.LineChart;
  41. import javafx.scene.chart.NumberAxis;
  42. import javafx.scene.chart.ScatterChart;
  43. import javafx.scene.chart.XYChart;
  44. import javafx.stage.Stage;
  45.  
  46. /**
  47.  * An advanced scatter chart with a variety of controls.
  48.  *
  49.  * @see javafx.scene.chart.ScatterChart
  50.  * @see javafx.scene.chart.Chart
  51.  * @see javafx.scene.chart.Axis
  52.  * @see javafx.scene.chart.NumberAxis
  53.  */
  54. public class ChartAdvancedScatter extends Application {
  55.  
  56.     private void init(Stage primaryStage) {
  57.         Group root = new Group();
  58.         primaryStage.setScene(new Scene(root));
  59.         root.getChildren().add(createQuadraticPolynomialChart());
  60.     }
  61.  
  62.     protected ScatterChart<Number, Number> createChart() {
  63.         final NumberAxis xAxis = new NumberAxis();
  64.         xAxis.setSide(Side.TOP);
  65.         final NumberAxis yAxis = new NumberAxis();
  66.         yAxis.setSide(Side.RIGHT);
  67.         final ScatterChart<Number,Number> sc = new ScatterChart<Number,Number>(xAxis,yAxis);
  68.         // setup chart
  69.         xAxis.setLabel("X Axis");
  70.         yAxis.setLabel("Y Axis");
  71.         // add starting data
  72.         for (int s=0;s<5;s++) {
  73.             XYChart.Series<Number, Number> series = new XYChart.Series<Number, Number>();
  74.             series.setName("Data Series");
  75. //            series.setName("Data Series "+s);
  76. //            for (int i=0; i<30; i++) series.getData().add(new XYChart.Data<Number, Number>(Math.random()*98, Math.random()*98));
  77. //            sc.getData().add(series);
  78.         }
  79.         return sc;
  80.     }
  81.  
  82.     protected LineChart<Number, Number> createConstantLinearFunction()
  83.     {
  84.         final NumberAxis xAxis = new NumberAxis();
  85.         xAxis.setSide(Side.TOP);
  86.         final NumberAxis yAxis = new NumberAxis();
  87.         yAxis.setSide(Side.RIGHT);
  88.         final LineChart<Number,Number> sc = new LineChart<Number,Number>(xAxis,yAxis);
  89.         // setup chart
  90.         xAxis.setLabel("X Axis");
  91.         yAxis.setLabel("Y Axis");
  92.         // add starting data
  93.         XYChart.Series<Number, Number> series = new XYChart.Series<Number, Number>();
  94.         series.setName("Data Series");
  95.         HashMap<Number, Number> chartElements = Functions.LinearFunction(30);
  96.         for(Map.Entry<Number, Number> chartElement : chartElements.entrySet())
  97.         {
  98.                 series.getData().add(new XYChart.Data<Number, Number>(chartElement.getKey(), chartElement.getValue()));
  99.         }
  100.        
  101.         sc.getData().add(series);
  102.         return sc;
  103.     }
  104.     protected LineChart<Number, Number> createQuadraticFunctionChart()
  105.     {
  106.         final NumberAxis xAxis = new NumberAxis();
  107.         xAxis.setSide(Side.TOP);
  108.         final NumberAxis yAxis = new NumberAxis();
  109.         yAxis.setSide(Side.RIGHT);
  110.         final LineChart<Number,Number> sc = new LineChart<Number,Number>(xAxis,yAxis);
  111.         // setup chart
  112.         xAxis.setLabel("X Axis");
  113.         yAxis.setLabel("Y Axis");
  114.         // add starting data
  115.         XYChart.Series<Number, Number> series = new XYChart.Series<Number, Number>();
  116.         series.setName("Data Series");
  117.         HashMap<Number, Number> chartElements = Functions.QuadraticFunction(30);
  118.         for(Map.Entry<Number, Number> chartElement : chartElements.entrySet())
  119.         {
  120.                 series.getData().add(new XYChart.Data<Number, Number>(chartElement.getKey(), chartElement.getValue()));
  121.         }
  122.        
  123.         sc.getData().add(series);
  124.         return sc;
  125.     }
  126.     protected LineChart<Number, Number> createQuadraticPolynomialChart()
  127.     {
  128.         final NumberAxis xAxis = new NumberAxis();
  129.         xAxis.setSide(Side.TOP);
  130.         final NumberAxis yAxis = new NumberAxis();
  131.         yAxis.setSide(Side.RIGHT);
  132.         final LineChart<Number,Number> sc = new LineChart<Number,Number>(xAxis,yAxis);
  133.         // setup chart
  134.         xAxis.setLabel("X Axis");
  135.         yAxis.setLabel("Y Axis");
  136.         // add starting data
  137.         XYChart.Series<Number, Number> series = new XYChart.Series<Number, Number>();
  138.         series.setName("Data Series");
  139.         HashMap<Number, Number> chartElements = Functions.PolynomialFunction(30);
  140.         for(Map.Entry<Number, Number> chartElement : chartElements.entrySet())
  141.         {
  142.                 series.getData().add(new XYChart.Data<Number, Number>(chartElement.getKey(), chartElement.getValue()));
  143.         }
  144.        
  145.         sc.getData().add(series);
  146.         return sc;
  147.     }
  148.     @Override public void start(Stage primaryStage) throws Exception {
  149.         init(primaryStage);
  150.         primaryStage.show();
  151.     }
  152.  
  153.     /**
  154.      * The main() method is ignored in correctly deployed JavaFX
  155.      * application. main() serves only as fallback in case the
  156.      * application can not be launched through deployment artifacts,
  157.      * e.g., in IDEs with limited FX support. NetBeans ignores main().
  158.      * @param args the command line arguments
  159.      */
  160.     public static void main(String[] args) {
  161.         launch(args);
  162.     }
  163. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement