在本页

LineSeries QML Type

用折线图表示数据。更多

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

XYSeries

属性

信号

方法

详细说明

折线图用于将信息显示为一系列由直线或阶梯连接的数据点。

序列可以包含间隙,使用 NaN 值,如 ......:

import QtGraphs

GraphsView {
    axisX: ValueAxis {
        max: 5
    }
    axisY: ValueAxis {
        max: 5
    }

    LineSeries {
        color: "#00ff00"
        joinStyle: Qt.RoundJoin

        XYPoint {
            x: 0.5
            y: 0.5
        }

        XYPoint {
            x: 1.1
            y: NaN
        }

        XYPoint {
            x: 1.9
            y: 3.3
        }

        XYPoint {
            x: 2.1
            y: 2.1
        }

        XYPoint {
            x: 5
            y: 4.9
        }
    }
}

QLineSeries *series = new QLineSeries();
series->append(0, 2);
series->append(2, 4);
series->append(3, std::numeric_limits<qreal>::quiet_NaN());
series->append(4, 1);
series->append(5, 0);
series->setLineStyle(QLineSeries::LineStyle::StepCenter);
series->setColor(Qt::red);

的结果是 :

注意: 如上面示例中的第一个图形所示,单独的点(如系列的第一个点)不会以直线形式显示,除非有一个可见的"......"。pointDelegate

LineSeries 使用的 API 与ScatterSeries 大致相同,因此更多使用示例请参见ScatterSeries 文档。

另请参见 ScatterSeries

属性文档

capStyle : Qt::PenCapStyle

控制线条的上限样式。设置为Qt.FlatCapQt.SquareCapQt.RoundCap 之一。默认情况下,线帽样式为 Qt.SquareCap。无效值将自动设置为默认值。

另请参阅 Qt::PenCapStyle

dashOffset : real [since 6.11]

该属性定义了破折号图案的起点,以用于指定破折号图案的单位来衡量。

默认值为0

此属性在 Qt 6.11 中引入。

dashPattern : list<real> [since 6.11]

strokeStyle 设置为LineSeries::DashLine 时,该属性定义破折号模式。该模式必须指定为偶数个正数,其中 1、3、5......为破折号,2、4、6......为空格。模式以行宽为单位指定。

默认值为 (4,2),即一个 4 *width 像素的破折号后跟一个 2 *width 像素的空格。

此属性在 Qt 6.11 中引入。

joinStyle : Qt::PenJoinStyle [since 6.11]

控制线条的连接样式。设置为Qt.BevelJoinQt.MiterJoinQt.RoundJoin 之一。默认情况下,连接样式为 Qt.BevelJoin。无效值将自动设置为默认值。

此属性在 Qt 6.11 中引入。

另请参阅 Qt::PenJoinStyle

lineStyle : QLineSeries::LineStyle [since 6.11]

控制线条的样式。设置为LineSeries.Straight,LineSeries.StepLeft,LineSeries.StepRightLineSeries.StepCenter 之一。默认情况下,线条样式为LineSeries.Straight。无效值将自动设置为默认值。

此属性在 Qt 6.11 中引入。

另请参阅 QLineSeries::LineStyle

pointDelegate : Component

用给定的 QML 组件标记点。

pointDelegate: Image {
    source: "images/happy_box.png"
}

strokeStyle : enumeration [since 6.11]

常数说明
LineSeries.SolidLine普通线条。
LineSeries.DashLine由几个像素分隔的破折号。

此属性在 Qt 6.11 中引入。

width : real

行的宽度。默认情况下,宽度为 2.0。宽度小于 0 时无效,会自动设置为 0。

信号文档

capStyleChanged()

当行列标题样式发生变化时发出该信号。

注: 相应的处理程序是onCapStyleChanged

[since 6.11] dashOffsetChanged(qreal newDashOffset)

该信号在行序列行破折号偏移发生变化时发出。newDashOffset 参数包含新的破折号偏移量。

注: 相应的处理程序是onDashOffsetChanged

此信号在 Qt 6.11 中引入。

[since 6.11] dashPatternChanged(QList<qreal> newDashPattern)

当系列行的破折号模式发生变化时,就会发出该信号。newDashPattern 参数包含新的破折号模式。

注: 相应的处理程序是onDashPatternChanged

此信号在 Qt 6.11 中引入。

[since 6.11] joinStyleChanged(Qt::PenJoinStyle newJoinStyle)

行序列盖样式发生变化时发出该信号。newJoinStyle 参数包含新的连接样式。

注: 相应的处理程序是onJoinStyleChanged

此信号在 Qt 6.11 中引入。

[since 6.11] lineStyleChanged(QLineSeries::LineStyle newLineStyle)

当行系列的行样式发生变化时会发出该信号。newLineStyle 参数包含新的线条样式。

注: 相应的处理程序是onLineStyleChanged

此信号在 Qt 6.11 中引入。

[since 6.11] strokeStyleChanged(QLineSeries::StrokeStyle newStrokeStyle)

当线条系列的笔画样式发生变化时会发出该信号。newStrokeStyle 参数包含新的笔划样式。

注: 相应的处理程序是onStrokeStyleChanged

此信号在 Qt 6.11 中引入。

widthChanged()

行序列宽度发生变化时发出此信号。

注: 相应的处理程序是onWidthChanged

方法文档

point dataPointCoordinatesAt(real x, real y)

返回转换为数据点坐标的xy 渲染坐标。

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