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

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

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

相关推荐
国服第二切图仔8 小时前
Qt-for-鸿蒙PC-多线程绘制开源鸿蒙开发实践
qt·开源·鸿蒙pc
国服第二切图仔10 小时前
Qt-for-鸿蒙PC-CheckBox开源鸿蒙开发实践
qt·开源·鸿蒙pc
喵个咪12 小时前
Qt 优雅实现线程安全单例模式(模板化 + 自动清理)
c++·后端·qt
离离茶17 小时前
【笔记1-8】Qt bug记录:QListWidget窗口的浏览模式切换为ListMode后,滚轮滚动速度变慢
笔记·qt·bug
共享家952721 小时前
QT-系统(文件)
开发语言·qt·命令模式
IT从业者张某某1 天前
Qt-for-鸿蒙PC-TextEditorPro 多功能文本编辑器开源鸿蒙开发实践
qt·开源·harmonyos
IT从业者张某某1 天前
Qt-for-鸿蒙PC-验证码组件开发实战
开发语言·qt·harmonyos
全栈陈序员1 天前
Qt for HarmonyOS/weather 天气应用项目
开发语言·qt·华为·harmonyos
风闲12171 天前
Qt源码编译记录
开发语言·qt
864记忆1 天前
Qt c++的基础语法有哪些?
开发语言·c++·qt