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();
}

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

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

相关推荐
扶尔魔ocy9 小时前
【qt openGL入门笔记】FPS相机
qt·opengl
扶尔魔ocy11 小时前
qt openGL入门笔记】FPS相机和轨道相机
qt·opengl
尘客-追梦12 小时前
qmake / jom / 影子构建:把编译管起来
开发语言·c++·qt
qeen8712 小时前
【QT】 信号与槽初始
开发语言·笔记·qt·学习
Quz2 天前
QML PathView:吸附对齐与环形轮播
qt
时间的拾荒人2 天前
Qt 多线程详解:从 QThread 到实战
开发语言·qt·面试
时间的拾荒人2 天前
Qt 事件机制全解析:从事件处理到事件过滤器
开发语言·qt·面试
时间的拾荒人2 天前
Qt 窗口系统详解:从菜单栏到对话框的完整指南
开发语言·qt·面试
qq_401700412 天前
Qt 炫酷曲线,图表,2D/3D开源库
开发语言·qt
扶尔魔ocy2 天前
【qt openGL入门笔记】基础光照
qt·opengl