PieSeries QML Type

用饼图显示数据。更多

Import Statement: import QtCharts 2.9
In C++: QPieSeries
Inherits:

AbstractSeries

属性

信号

方法

  • PieSlice append(string label, real value)
  • PieSlice at(int index)
  • clear()
  • PieSlice find(string label)
  • bool remove(PieSlice slice)

详细说明

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

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

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

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

ChartView {
    id: chart
    title: "Top-5 car brand shares in Finland"
    anchors.fill: parent
    legend.alignment: Qt.AlignBottom
    antialiasing: true

    property variant othersSlice: 0

    PieSeries {
        id: pieSeries
        PieSlice { label: "Volkswagen"; value: 13.5 }
        PieSlice { label: "Toyota"; value: 10.9 }
        PieSlice { label: "Ford"; value: 8.6 }
        PieSlice { label: "Skoda"; value: 8.2 }
        PieSlice { label: "Volvo"; value: 6.8 }
    }

    Component.onCompleted: {
        // You can also manipulate slices dynamically, like append a slice or set a slice exploded
        othersSlice = pieSeries.append("Others", 52.0);
        pieSeries.find("Volkswagen").exploded = true;
    }
}


另请参阅 PieSliceChartView

属性文档

count : int [read-only]

系列中的切片数。


endAngle : real

饼的结束角度。

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

默认值为 360 度。


holeSize : real

甜甜圈洞的大小。

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

  • 0.0 是最小尺寸(绘制的全饼没有孔)。
  • 1.0 是适合图表的最大尺寸(甜甜圈没有宽度)。

设置此属性时,如有必要,可调整size 属性,以确保孔的大小不大于饼的大小。

默认值为 0.0。


horizontalPosition : real

饼的水平位置。

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

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

默认值为 0.5(居中)。

另请参阅 verticalPosition


size : real

饼的大小。

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

  • 0.0 是最小尺寸(不绘制饼)。
  • 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

注: 相应的处理程序是onAdded


clicked(PieSlice slice)

点击slice 指定的切片时,会发出此信号。

相应的信号处理程序是onClicked

注: 相应的处理程序是onClicked


doubleClicked(PieSlice slice)

双击slice 指定的切片时,会发出该信号。

相应的信号处理程序是onDoubleClicked

注: 相应的处理程序是onDoubleClicked


hovered(PieSlice slice, bool state)

当鼠标悬停在slice 指定的片上时,将发出该信号。当鼠标移动到切片上时,state 会变成true ,当鼠标再次移开时,它会变成false

相应的信号处理程序是onHovered

注: 相应的处理程序是onHovered


pressed(PieSlice slice)

当用户点击slice 指定的切片并按住鼠标键时,将发出该信号。

相应的信号处理程序是onPressed

注: 相应的处理程序是onPressed


released(PieSlice slice)

当用户松开slice 指定的切片上的鼠标键时,将发出该信号。

相应的信号处理器是onReleased

注: 相应的处理程序是onReleased


removed(list<PieSlice> slices)

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

相应的信号处理程序是onRemoved

注: 相应的处理程序是onRemoved


sliceAdded(PieSlice slice)

slice 指定的片段添加到系列时,将发出该信号。

相应的信号处理程序是onSliceAdded

注: 相应的处理程序是onSliceAdded


sliceRemoved(PieSlice slice)

slice 指定的片段从系列中删除时,将发出该信号。

相应的信号处理程序是onSliceRemoved

注: 相应的处理程序是onSliceRemoved


方法文档

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


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