如何在 JavaFX XY 圖表中移除刻度標籤?
javafx.scene.XYChart 類是所有在 x-y 平面中繪製的圖表的基類。透過例項化此類的子類,您可以建立各種 XY 圖表,例如 - 線形圖、面積圖、條形圖、餅圖、氣泡圖、散點圖等。
在 XY 圖表中,給定的資料點繪製在 XY 平面上。在 x 和 y 軸上,您將有刻度標記和標籤。標籤指定值的名稱(或數字)。

更改刻度標記的顏色
javafx.scene.chart.Axis 類(抽象)是 XY 圖表中所有軸的基類。要建立 X 和 Y 軸,您需要例項化這些類的子類。
NumberAxis 類用於建立數值軸,而 CategoryAxis 類用於建立字串類別的軸。
此類有一個名為 tickLabelVisible(布林型)的屬性,它指定是否顯示刻度標記。您可以使用 setTickLabelVisible() 方法設定此屬性的值。
要移除 XY 圖表的刻度標籤,請透過傳遞布林值 false 呼叫此方法。
示例
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.scene.layout.StackPane;
public class RemovingTickLabels extends Application {
public void start(Stage stage) {
//Defining the x an y axes
CategoryAxis xAxis = new CategoryAxis();
NumberAxis yAxis = new NumberAxis(200, 600, 100);
//Setting labels for the axes
xAxis.setLabel("Model");
yAxis.setLabel("Price (USD)");
//Creating a line chart
LineChart linechart = new LineChart(xAxis, yAxis);
//Preparing the data points for the line
XYChart.Series series = new XYChart.Series();
series.getData().add(new XYChart.Data("OnePlus X", 249));
series.getData().add(new XYChart.Data("OnePlus One", 299));
series.getData().add(new XYChart.Data("OnePlus 2", 329));
series.getData().add(new XYChart.Data("OnePlus 3", 399));
series.getData().add(new XYChart.Data("OnePlus 3T", 439));
series.getData().add(new XYChart.Data("OnePlus 5", 479));
series.getData().add(new XYChart.Data("OnePlus 5T", 499));
series.getData().add(new XYChart.Data("OnePlus 6", 559));
//Setting the name to the line (series)
series.setName("Price of mobiles");
//Setting the data to Line chart
linechart.getData().add(series);
//Removing the tick labels
xAxis.setTickLabelsVisible(false);
yAxis.setTickLabelsVisible(false);
//Creating a stack pane to hold the chart
StackPane pane = new StackPane(linechart);
pane.setPadding(new Insets(15, 15, 15, 15));
pane.setStyle("-fx-background-color: BEIGE");
//Setting the Scene
Scene scene = new Scene(pane, 595, 300);
stage.setTitle("JavaFX Example");
stage.setScene(scene);
stage.show();
}
public static void main(String args[]){
launch(args);
}
}輸出

廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP