首页 > 其他分享 > QLineSeries和 QBarSeries的用法

QLineSeries和 QBarSeries的用法

时间:2022-12-31 15:31:40浏览次数:43  
标签:QBarSet QBarSeries chart 用法 barseries QLineSeries new lineseries append


#include <QtWidgets/QApplication>
#include <QtWidgets/QMainWindow>
#include <QtCharts/QChartView>
#include <QtCharts/QBarSeries>
#include <QtCharts/QBarSet>
#include <QtCharts/QLineSeries>
#include <QtCharts/QLegend>
#include <QtCharts/QBarCategoryAxis>
#include <QtCharts/QValueAxis>

QT_CHARTS_USE_NAMESPACE

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


QBarSet *set0 = new QBarSet("Jane");
QBarSet *set1 = new QBarSet("John");
QBarSet *set2 = new QBarSet("Axel");
QBarSet *set3 = new QBarSet("Mary");
QBarSet *set4 = new QBarSet("Sam");

*set0 << 1 << 2 << 3 << 4 << 5 << 6;
*set1 << 5 << 0 << 0 << 4 << 0 << 7;
*set2 << 3 << 5 << 8 << 13 << 8 << 5;
*set3 << 5 << 6 << 7 << 3 << 4 << 5;
*set4 << 9 << 7 << 5 << 3 << 1 << 2;
QBarSeries *barseries = new QBarSeries();
barseries->append(set0);
barseries->append(set1);
barseries->append(set2);
barseries->append(set3);
barseries->append(set4);

QLineSeries *lineseries = new QLineSeries();
lineseries->setName("trend");
lineseries->append(QPoint(0, 4));
lineseries->append(QPoint(1, 15));
lineseries->append(QPoint(2, 20));
lineseries->append(QPoint(3, 4));
lineseries->append(QPoint(4, 12));
lineseries->append(QPoint(5, 17));

QChart *chart = new QChart();
chart->addSeries(barseries);
chart->addSeries(lineseries);
chart->setTitle("Line and barchart example");

QStringList categories;
categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
QBarCategoryAxis *axisX = new QBarCategoryAxis();
axisX->append(categories);
chart->addAxis(axisX, Qt::AlignBottom);
lineseries->attachAxis(axisX);
barseries->attachAxis(axisX);
axisX->setRange(QString("Jan"), QString("Jun"));

QValueAxis *axisY = new QValueAxis();
chart->addAxis(axisY, Qt::AlignLeft);
lineseries->attachAxis(axisY);
barseries->attachAxis(axisY);
axisY->setRange(0, 20);

chart->legend()->setVisible(true);
chart->legend()->setAlignment(Qt::AlignBottom);

QChartView *chartView = new QChartView(chart);
chartView->setRenderHint(QPainter::Antialiasing);

QMainWindow window;
window.setCentralWidget(chartView);
window.resize(440, 300);
window.show();

return a.exec();
}

 QLineSeries和 QBarSeries的用法_Qt

标签:QBarSet,QBarSeries,chart,用法,barseries,QLineSeries,new,lineseries,append
From: https://blog.51cto.com/u_15515702/5982134

相关文章

  • QDialogButtonBox的用法
    #include"dialog.h"#include<QtNetwork>#include<QtWidgets>staticconstintTotalBytes=50*1024*1024;staticconstintPayloadSize=64*1024;//64KBDial......
  • sqlite 多列多行转置到单行的用法
    1、sqlite:group_concat()多列 参考https://qa.1r1g.com/sf/ask/685814741/SELECTstep,group_concat(concat)ASformatedFROM(SELECTstep,......
  • dataset 用法
       ADO.NetDataAdapter类-ADO.Net教程(yiibai.com) ......
  • curl 命令用法
    curl命令用法目录curl命令用法简介常用命令不带参数:发出GET请求-A参数:用来指定客户端的用户代理标头,即User-Agent。curl的默认用户代理字符串是curl/[version]。-b......
  • window.open用法详解
    window.open用法详解夕山雨于2020-08-0917:44:52发布49906收藏111分类专栏:js基础文章标签:window.open版权华为云开发者联盟该内容已被华为云开发者联......
  • 爬虫之 xPath 用法总结整理
    在网络爬虫中,对于HTML的解析,XPath是一种常用的方法。XPath最初是用于XML中,其主要使用路径表达式在XML文档中进行导航。用于HTML中主要是因为HTML和XML非常的相似:它们具有......
  • SAP实战中Submit的常见用法(方法二挺好用的,标准,自定义报表都可以用)
    场景:系统MB52/MB51/MB5B等类似的报表,虽然数据很全面,执行效率也够快,但是经常会不满足用户需求(增添字段、添加查询条件等),很多ABAP会选择去COPY出标准程序,然后去做修改,强烈不......
  • MySQL的group_concat()函数简单用法
    将groupby产生的同一个分组中的值连接起来,返回一个字符串结果。group_concat函数首先根据groupby指定的列进行分组,将同一组的列显示出来,并且用分隔符分隔。由函数参数(字......
  • python的list的用法
    #ReadMe#本工具是根据用户选择的条目来打印该列表下的内容#例如选择“北京”就会打印北京下面的“海淀”“昌平”“朝阳”,选择“海淀”然后会打印海淀下面的“清华大学”和......
  • lombok之@Accessors用法
    lombok之@Accessors用法lombok的@Accessors注解,打在pojo类上,实现setter方法的链式调用,特别是在初始化对象实例时,可以实现@Builder注解的部分功能,非常方便。注意:有些框架,......