qt QLineSeries详解

1、概述

QLineSeries是Qt Charts模块中的一个重要类,用于绘制折线图。它是QXYSeries的实现类,将信息显示为由直线连接的一系列数据点。该类为QAbstractSeries的子类,因此可以通过该类来访问QAbstractSeries的所有公共方法和属性。

2、重要方法

  • chart() :返回 QChartView 当前设置的 QChart 类对象。
  • append(qreal x, qreal y):向折线图中添加一个数据点。

  • append(const QPointF &point):向折线图中添加一个数据点。

  • append(const QList<QPointF>:向折线图中批量添加多个数据点。

  • at(int index) const : const QPointF &:获取指定索引位置的数据点。

  • **attachAxis(QAbstractAxis axis) : bool:**将一个坐标轴附加到折线图上。

  • attachedAxes() : QList<QAbstractAxis *>:获取所有附加到折线图的坐标轴。

  • **clear():**清除数据序列中的所有点。

  • **count():**返回数据序列中点的数量。

  • **remove(int index):**从数据序列中移除指定索引处的点。

  • **replace(int index, qreal x, qreal y):**替换数据序列中指定索引处的点。

  • **setPen(const QPen &pen):**设置图表上绘制点的画笔。

  • **setBrush(const QBrush &brush):**设置图表上绘制点的画刷。

3、实例

复制代码
#include <QApplication>
#include <QtCharts/QChartView>
#include <QtCharts/QLineSeries>
#include <QtCharts/QValueAxis>
QT_CHARTS_USE_NAMESPACE

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QLineSeries *series = new QLineSeries();
    series->append(0, 6);
    series->append(2, 4);
    series->append(3, 8);
    series->append(7, 4);
    series->append(10, 5);
    QChart *chart = new QChart();
    chart->addSeries(series);
    chart->setTitle("Simple Line Chart Example");
    chart->createDefaultAxes();
    QChartView *chartView = new QChartView(chart);
    chartView->setRenderHint(QPainter::Antialiasing);

    QMainWindow window;
    window.setCentralWidget(chartView);
    window.resize(800, 600);
    window.show();

    return a.exec();
}

觉得有帮助的话,打赏一下呗。。

需要商务合作(定制程序)的欢迎私信!!

相关推荐
范特西.i5 天前
QT聊天项目(8)
开发语言·qt
枫叶丹45 天前
【Qt开发】Qt界面优化(七)-> Qt样式表(QSS) 样式属性
c语言·开发语言·c++·qt
十五年专注C++开发5 天前
Qt deleteLater作用及源码分析
开发语言·c++·qt·qobject
kangzerun5 天前
SQLiteManager:一个优雅的Qt SQLite数据库操作类
数据库·qt·sqlite
金刚狼885 天前
qt和qt creator的下载安装
开发语言·qt
追烽少年x5 天前
Qt中使用Zint库显示二维码
qt
谁刺我心5 天前
qt源码、qt在线安装器镜像下载
开发语言·qt
金刚狼885 天前
在qt creator中创建helloworld程序并构建
开发语言·qt
扶尔魔ocy6 天前
【转载】QT使用linuxdeployqt打包
开发语言·qt
YxVoyager6 天前
在VS2017中使用Qt的foreach宏,IntelliSense无法正确识别函数定义
c++·qt