PieSeries QML Type

用饼图展示数据。更多

Import Statement: import QtGraphs
In C++: QPieSeries
Inherits:

AbstractSeries

属性

信号

方法

  • PieSlice append(string label, real value)
  • PieSlice at(int index)
  • clear()
  • PieSlice find(string label)
  • bool remove(PieSlice slice)
  • bool remove(int index)
  • void removeMultiple(int index, int count)
  • bool replace(list<PieSlice> slices)
  • bool replace(PieSlice oldSlice, PieSlice newSlice)
  • bool replace(int index, PieSlice slice)
  • bool take(PieSlice slice)

详细说明

饼系列由使用PieSlice 类型定义的切片组成。切片可以有任何值,因为 PieSeries 类型会计算切片与系列中所有切片总和的百分比,以确定图形中切片的实际大小。

饼的大小和在图表中的位置是通过使用 0.0 到 1.0 之间的相对值来控制的。这些值与实际图形矩形有关。

默认情况下,饼被定义为完整饼。通过设置系列的起始角度和角度跨度,可以创建部分饼。全饼为 360 度,其中 0 位于 12 点钟位置。

下面的 QML 示例展示了如何创建一个简单的饼图。

import QtQuick
import QtGraphs

Item {
    id: mainView
    width: 1280
    height: 720

    GraphsView {
        anchors.fill: parent
        theme: GraphsTheme {
             colorScheme: GraphsTheme.ColorScheme.Dark
             theme: GraphsTheme.Theme.QtGreen
        }
        PieSeries {
            id: pieSeries
            PieSlice {
                value: 1
            }
            PieSlice {
                value: 2
            }
        }
    }
}

另请参阅 PieSliceGraphsView

属性文档

count : int [read-only]

系列中的切片数。


endAngle : real

饼的结束角度。

一个完整的饼是 360 度,其中 0 度在 12 点钟位置。

默认值为 360 度。


holeSize : real

甜甜圈洞的大小。

在设置pieSize 属性时,如有必要,会对该属性进行调整,以确保孔的大小不大于派的大小。

默认值为 0.0。


horizontalPosition : real

饼的水平位置。

该值是相对于图形矩形而言的,因此

  • 0.0 表示绝对左侧。
  • 1.0 为绝对向右。

默认值为 0.5(居中)。

另请参阅 verticalPosition


pieSize : real

饼的大小。

该值相对于图形矩形,因此

  • 0.0 是最小 pieSize(不绘制饼)。
  • 1.0 是适合图形的最大饼大小。

设置此属性时,必要时会调整holeSize 属性,以确保孔的大小不大于饼的大小。

默认值为 0.7。


startAngle : real

饼的起始角度。

一个完整的饼是 360 度,其中 0 度为 12 点钟位置。

默认值为 0。


sum : real [read-only]

所有切片的总和。

饼系列会记录所有饼片的总和。


verticalPosition : real

饼的垂直位置。

该值相对于图表矩形,因此

  • 0.0 为绝对顶部。
  • 1.0 为绝对底部。

默认值为 0.5(居中)。

另请参阅 horizontalPosition


信号文档

added(list<PieSlice> slices)

slices 指定的切片添加到系列时,将发出此信号。

注: 相应的处理程序是onAdded


clicked(PieSlice slice)

点击或敲击slice 时发出该信号。

注: 相应的处理程序是onClicked


countChanged()

当切片计数发生变化时,将发出此信号。

注: 相应的处理程序是onCountChanged

另请参阅 count


doubleClicked(PieSlice slice)

双击或轻敲slice 时发出此信号。该信号总是出现在clicked 之后。

注: 相应的处理程序是onDoubleClicked


endAngleChanged()

饼端角发生变化时发出此信号。

注: 相应的处理程序是onEndAngleChanged

另请参阅 endAngle


holeSizeChanged()

甜甜圈孔大小发生变化时会发出此信号。

注: 相应的处理程序是onHoleSizeChanged

另请参阅 holeSize


horizontalPositionChanged()

水平位置发生变化时会发出该信号。

注: 相应的处理程序是onHorizontalPositionChanged

另请参见 horizontalPosition


pieSizeChanged()

饼的大小发生变化时会发出此信号。

注: 相应的处理程序是onPieSizeChanged

另请参阅 pieSize


pressed(PieSlice slice)

当用户单击或轻点slice 并按住鼠标按钮或手势时,将发出该信号。

注: 相应的处理程序是onPressed


released(PieSlice slice)

当用户在slice 上释放先前按下的鼠标按钮或手势时,会发出该信号。

注: 相应的处理程序是onReleased


removed(list<PieSlice> slices)

slices 指定的切片从系列中移除时,将发出该信号。

注: 相应的处理程序是onRemoved


startAngleChanged()

当饼的起始角度发生变化时,将发出此信号。

注: 相应的处理程序是onStartAngleChanged

另请参阅 startAngle


sumChanged()

当所有切片的总和发生变化时,会发出该信号。

注: 相应的处理程序是onSumChanged

另请参见 sum


verticalPositionChanged()

垂直位置发生变化时会发出该信号。

注: 相应的处理程序是onVerticalPositionChanged

另请参见 verticalPosition


方法文档

PieSlice append(string label, real value)

向饼中添加标签为label 、值为value 的新切片。


PieSlice at(int index)

返回index 指定位置的切片。如果索引无效,则返回 null。


clear()

从饼中删除所有切片。


PieSlice find(string label)

返回第一个标签为label 的切片。如果找不到标签,则返回空值。


bool remove(PieSlice slice)

从馅饼中移除slice 指定的切片。如果删除成功,则返回true ,否则返回false


bool remove(int index)

从饼中删除index 指定的切片。如果删除成功,则返回true ,否则返回false


void removeMultiple(int index, int count)

删除indexcount 指定的一系列切片。即使删除失败,调用也会遍历所有切片。


bool replace(list<PieSlice> slices)

slices 完全替换当前的所有片段。大小无需匹配。如果slices 中的任何PieSlice 无效,则返回 false。


bool replace(PieSlice oldSlice, PieSlice newSlice)

用 newSlice 替换oldSlice 指定的切片。如果移除成功,则返回true ,否则返回false 。如果移除成功,则销毁oldSlice


bool replace(int index, PieSlice slice)

index 的派中替换slice 指定的切片。如果替换成功,则返回true ,否则返回false


bool take(PieSlice slice)

从系列中提取slice 指定的单个切片。不会删除切片对象。如果成功,则返回true


© 2025 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.