Sample_TrendGraph.java
を以下に示します。/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package sample_trendgraph; import javafx.application.Application; 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.scene.effect.DropShadow; import javafx.scene.layout.StackPane; import javafx.scene.paint.Color; import javafx.stage.Stage; /** * * @author bitwalk */ public class Sample_TrendGraph extends Application { @Override public void start(Stage primaryStage) { final NumberAxis xAxis = new NumberAxis(0, 100, 10); final NumberAxis yAxis = new NumberAxis(-1, 1, 0.1); final LineChartgrp = new LineChart<>(xAxis, yAxis); grp.setCreateSymbols(true); grp.setAlternativeRowFillVisible(false); grp.setPrefSize(600, 400); grp.setTitle("トレンドチャート"); xAxis.setLabel("時間軸"); yAxis.setLabel("データ値"); DropShadow shadow = new DropShadow(); shadow.setOffsetX(2); shadow.setColor(Color.GREY); grp.setEffect(shadow); final XYChart.Series series1 = new XYChart.Series(); series1.setName("系列1"); for (int i = 0; i <= 100; i++) { series1.getData().add( new ScatterChart.Data (i, (Math.random() - 0.5) * 1.6)); } grp.getData().addAll(series1); StackPane root = new StackPane(); root.getChildren().add(grp); Scene scene = new Scene(root); scene.getStylesheets().add(Sample_TrendGraph.class.getResource("Chart.css").toExternalForm()); primaryStage.setTitle("トレンドチャート"); primaryStage.setScene(scene); 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); } }
Chart.css
を以下に示します。
.chart-series-line { -fx-stroke-width: 1px; -fx-effect: null; } .chart-plot-background { -fx-background-color: #E0FFFF; } .chart-vertical-grid-lines { -fx-stroke: #0000C0; } .chart-horizontal-grid-lines { -fx-stroke: #0000C0; } .default-color0.chart-series-line { -fx-stroke: #800000; } .default-color0.chart-line-symbol { -fx-background-color: #800000, #C04000; -fx-background-radius: 0; -fx-background-insets: 1px; -fx-shape: "M2,2 L2,-2 -2,-2 -2,2 Z"; }
実行例を以下に示しました。