如何在 JavaFX XY 图表中移除刻度标记?
javafx.scene.XYChart 类是所有在 x-y 平面中绘制的图表的基本类。通过实例化此类的子类,您可以创建各种 XY 图表,例如 - 线形图、面积图、柱状图、饼图、气泡图、散点图等。
在 XY 图表中,给定的数据点绘制在 XY 平面上。在 x 和 y 轴上,您将看到刻度标记和刻度标签。刻度标记代表具有统一间隔的各种值。

移除刻度标记
javafx.scene.chart.Axis 类(抽象类)是 XY 图表中所有轴的基本类。要创建 X 和 Y 轴,您需要实例化这些类的子类。
NumberAxis 类用于为数值创建轴,而 CategoryAxis 类用于为字符串类别创建轴。
此类具有一个名为 tickMarkVisible(布尔型)的属性,它指定是否显示刻度标记。您可以使用 setTickMarkVisible() 方法设置此属性的值。
要移除 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 RemovingTickMarks 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 marks
xAxis.setTickMarkVisible(false);
yAxis.setTickMarkVisible(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