JavaFX AreaChart

本文概述

  • 物产
  • 建设者
通常, 面积图用于显示图形化的定量数据。它基本上在XY平面上绘制点集的面积。它与折线图的不同之处在于折线图通过直线段将数据点连接在一起, 而不是绘制它们所占据的面积。
在下图中, 面积图显示一年中每个月两个不同的自行车消耗的汽油量。
JavaFX AreaChart

文章图片
在JavaFX中, 类javafx.scene.chart.AreaChart表示面积图。我们需要实例化此类以生成面积图节点。
物产 该类包含单个属性, 下表及其setter方法对此进行了描述。
属性 描述 设置方法
createSymbols 这是布尔类型的属性。其真实值指示为尚未指定符号节点的任何数据项创建符号。 setCreateSymbols(boolean value)
建设者 该类中有两个构造函数。
  1. public AreaChart(Axis Xaxis, Axis Yaxis):使用指定的Axis创建AreaChart的新实例。
  2. public AreaChart(轴X轴, 轴Y轴, ObservableList> 数据):使用指定的轴和数据创建AreaChart的新实例。

【JavaFX AreaChart】在以下示例中, 我们显示了公司在地区销售方面的比较。
package application; import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.chart.AreaChart; import javafx.scene.chart.NumberAxis; import javafx.scene.chart.XYChart; import javafx.stage.Stage; public class AreaChartTest extends Application {@Overridepublic void start(Stage primaryStage) throws Exception { // TODO Auto-generated method stub //Configuring Xaxis and Yaxis NumberAxis xaxis = new NumberAxis(1, 12, 1); NumberAxis yaxis = new NumberAxis(10, 510, 50); xaxis.setLabel("Month of the year"); yaxis.setLabel("Sales value (lacs)"); //Creating Areachart AreaChart< Number, Number> area = new AreaChart(xaxis, yaxis); //Setting title for areachart area.setTitle("RegionWise Sales"); //Configuring series for North sales XYChart.Series seriesNorth = new XYChart.Series(); seriesNorth.setName("North"); seriesNorth.getData().add(new XYChart.Data(1, 120)); seriesNorth.getData().add(new XYChart.Data(2, 140)); seriesNorth.getData().add(new XYChart.Data(3, 50)); seriesNorth.getData().add(new XYChart.Data(4, 80)); seriesNorth.getData().add(new XYChart.Data(5, 150)); seriesNorth.getData().add(new XYChart.Data(6, 130)); seriesNorth.getData().add(new XYChart.Data(7, 110)); seriesNorth.getData().add(new XYChart.Data(8, 90)); seriesNorth.getData().add(new XYChart.Data(9, 200)); seriesNorth.getData().add(new XYChart.Data(10, 120)); seriesNorth.getData().add(new XYChart.Data(11, 100)); seriesNorth.getData().add(new XYChart.Data(12, 120)); //Configuring series for East sales XYChart.Series seriesEast = new XYChart.Series(); seriesEast.setName("East"); seriesEast.getData().add(new XYChart.Data(1, 500)); seriesEast.getData().add(new XYChart.Data(2, 200)); seriesEast.getData().add(new XYChart.Data(3, 300)); seriesEast.getData().add(new XYChart.Data(4, 290)); seriesEast.getData().add(new XYChart.Data(5, 150)); seriesEast.getData().add(new XYChart.Data(6, 120)); seriesEast.getData().add(new XYChart.Data(7, 190)); seriesEast.getData().add(new XYChart.Data(8, 80)); seriesEast.getData().add(new XYChart.Data(9, 100)); seriesEast.getData().add(new XYChart.Data(10, 220)); seriesEast.getData().add(new XYChart.Data(11, 300)); seriesEast.getData().add(new XYChart.Data(12, 220)); //Configuring series for west sales XYChart.Series seriesWest = new XYChart.Series(); seriesWest.setName("West"); seriesWest.getData().add(new XYChart.Data(1, 320)); seriesWest.getData().add(new XYChart.Data(2, 40)); seriesWest.getData().add(new XYChart.Data(3, 250)); seriesWest.getData().add(new XYChart.Data(4, 10)); seriesWest.getData().add(new XYChart.Data(5, 190)); seriesWest.getData().add(new XYChart.Data(6, 140)); seriesWest.getData().add(new XYChart.Data(7, 200)); seriesWest.getData().add(new XYChart.Data(8, 190)); seriesWest.getData().add(new XYChart.Data(9, 300)); seriesWest.getData().add(new XYChart.Data(10, 130)); seriesWest.getData().add(new XYChart.Data(11, 400)); seriesWest.getData().add(new XYChart.Data(12, 220)); //Configuring series for south sales XYChart.Series seriesSouth = new XYChart.Series(); seriesSouth.setName("South"); seriesSouth.getData().add(new XYChart.Data(1, 220)); seriesSouth.getData().add(new XYChart.Data(2, 40)); seriesSouth.getData().add(new XYChart.Data(3, 250)); seriesSouth.getData().add(new XYChart.Data(4, 180)); seriesSouth.getData().add(new XYChart.Data(5, 450)); seriesSouth.getData().add(new XYChart.Data(6, 230)); seriesSouth.getData().add(new XYChart.Data(7, 110)); seriesSouth.getData().add(new XYChart.Data(8, 100)); seriesSouth.getData().add(new XYChart.Data(9, 123)); seriesSouth.getData().add(new XYChart.Data(10, 125)); seriesSouth.getData().add(new XYChart.Data(11, 225)); seriesSouth.getData().add(new XYChart.Data(12, 127)); //adding series to the Area chart area.getData().addAll(seriesNorth, seriesWest, seriesEast, seriesSouth); //setting Group and Scene Group root = new Group(area); Scene scene = new Scene(root, 600, 400); primaryStage.setScene(scene); primaryStage.setTitle("AreaChart Example"); primaryStage.show(); }public static void main(String[] args) {launch(args); }}

JavaFX AreaChart

文章图片

    推荐阅读