本页内容

GraphsView QML Type

所有Qt Graphs 视图的基类。更多...

Import Statement: import QtGraphs

属性

方法

详细说明

该类将数据序列和主题整合在一起,并绘制图表。要使用此类,您需要导入Qt Graphs 模块:

import QtGraphs

之后,您可以在 QML 文件中使用 GraphsView:

import QtQuick
import QtGraphs

GraphsView {
    anchors.fill: parent
    theme: GraphsTheme {
        colorScheme: GraphsTheme.ColorScheme.Dark
        seriesColors: ["#E0D080", "#B0A060"]
        borderColors: ["#807040", "#706030"]
        grid.mainColor: "#ccccff"
        grid.subColor: "#eeeeff"
        axisY.mainColor: "#ccccff"
        axisY.subColor: "#eeeeff"
    }
    axisX: BarCategoryAxis {
        categories: ["2023", "2024", "2025"]
        lineVisible: false
    }
    axisY: ValueAxis {
        min: 0
        max: 10
        subTickCount: 4
    }
    BarSeries {
        BarSet {
            values: [7, 6, 9]
        }
        BarSet {
            values: [9, 8, 6]
        }
    }
}

显示2023年、2024年和2025年数据的柱状图

另请参阅 BarSeries 、LineSeries 、BarCategoryAxis 、ValueAxis 以及GraphsTheme 。

属性文档

axisX : AbstractAxis

此视图中数据系列所使用的x轴。

注意: 不支持将 同一坐标轴设置 给多个 GraphsView。

另请参阅 axisY 。

axisXSmoothing : real

控制图表 X 轴的平滑(抗锯齿)程度。默认情况下,平滑程度为1.0 。

axisY : AbstractAxis

此视图中数据系列所使用的 y 轴。

注意: 不支持将 同一坐标轴设置 给多个 GraphsView。

另请参阅 axisX 。

axisYSmoothing : real

控制图表 Y 轴的平滑(抗锯齿)程度。默认情况下,平滑级别为1.0 。

clipPlotArea : bool [since 6.10]

控制图元是否应在超出绘图区域时被裁剪。默认值为true 。

该属性在 Qt 6.10 中引入。

另请参阅 plotArea 。

dynamicLabelMargins : bool

此属性控制标签边距是否动态调整。

默认情况下,宽度超过分配边距的标签会与其他图表元素重叠。启用此属性后,渲染器会为这类标签预留额外空间,并重新定位坐标轴以避免重叠。

gridSmoothing : real

控制图形网格平滑(抗锯齿)的程度。默认情况下,平滑程度为1.0 。

marginBottom : real

图表底部留白的空间大小。默认情况下,边距为 20。

marginLeft : real

图表左侧的空白区域大小。默认情况下,边距为 20。

marginRight : real

图表右侧的空白区域大小。默认情况下,边距为 20。

marginTop : real

图表顶部的空白区域大小。默认情况下,边距为 20。

orientation : Qt.Orientation

用于确定GraphsView 的布局方向。当布局方向为Qt.Horizontal 时,axisX 和axisY 将互换位置,使得axisX 以垂直方向渲染,axisY 以水平方向渲染。该属性目前由BarSeries 使用。默认值为Qt.Vertical 。

panStyle : enumeration [since 6.9]

确定GraphsView 的平移样式。平移功能通过操作ValueAxis 的pan属性来实现。默认值为GraphsView.PanStyle.None 。

常量描述
GraphsView.PanStyle.None禁用平移功能。
GraphsView.PanStyle.Drag通过鼠标和触摸拖动可平移视图。

该属性于 Qt 6.9 中引入。

plotArea : rect [read-only, since 6.9]

绘制图形所处的矩形区域。该区域为GraphsView 区域减去坐标轴区域和边距后的部分。

该属性在 Qt 6.9 中引入。

另请参阅 marginTop 、marginBottom 、marginLeft 以及marginRight 。

seriesList : list [read-only]

由GraphsView 渲染的系列列表。该列表会自动填充GraphsView 的系列类型子元素。

这是默认属性,因此子元素会自动添加到序列列表中。

另请参阅 BarSeries 、LineSeries 和ScatterSeries 。

shadowBarWidth : real

控制图表网格阴影的宽度。默认情况下,阴影宽度设置为2.0 。

shadowColor : color

控制图表网格的阴影颜色。默认情况下,阴影颜色设置为black 。

shadowSmoothing : real

控制图形网格阴影平滑(抗锯齿)的程度。默认情况下,阴影平滑设置为4.0 。

shadowVisible : bool

控制图表网格阴影是否可见。默认情况下,阴影可见性设置为false 。

shadowXOffset : real

控制图表网格阴影的 X 偏移量。默认情况下,阴影的 X 偏移量设置为0.0 。

shadowYOffset : real

控制图形网格阴影的 Y 偏移量。默认情况下,阴影的 Y 偏移量设置为0.0 。

theme : GraphsTheme

图表使用的主题。决定颜色、坐标轴线、字体等。如果未设置主题,则使用默认主题。

zoomAreaDelegate : Component [since 6.9]

确定当用户执行拖动操作以放大某个区域时,将绘制的 QML 元素。

该属性自 Qt 6.9 起引入。

zoomAreaEnabled : bool [since 6.9]

缩放区域会将鼠标和触控拖动转换为绘制一个由zoomAreaDelegate 确定的矩形框。松开鼠标或手指时,图表的ValueAxis 缩放和平移属性将随之改变,使得视图仅覆盖所绘矩形框所包围的区域。

该属性在 Qt 6.9 中引入。

另请参阅 zoomAreaDelegate 。

zoomSensitivity : real [since 6.9]

确定缩放过程中缩放值的变化速度。

该属性在 Qt 6.9 中引入。

zoomStyle : enumeration [since 6.9]

确定GraphsView 的缩放样式。缩放功能通过操作ValueAxis 的zoom属性来实现。默认值为GraphsView.ZoomStyle.None 。

常量描述
GraphsView.ZoomStyle.None禁用缩放功能。
GraphsView.ZoomStyle.Center双指缩放和鼠标滚轮缩放均以图表视图的中心为基准。

该属性自 Qt 6.9 起引入。

方法文档

void addSeries(AbstractSeries series)

将一个series 追加到GraphsView 中。如果series 为空,则不会进行追加。如果series 已属于该图,则将其移至末尾。

bool hasSeries(AbstractSeries series)

如果series 位于图中,则返回true 。

void insertSeries(int index, AbstractSeries series)

在index 指定的位置插入一个series 。如果series 为空,则不会插入。如果series 已属于该图,则将其移动到index 。

void removeSeries(AbstractSeries series)

从图中移除series 。

void removeSeries(int index)

从图中移除由index 指定的序列。

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.