[QtCharts]barchart_楼兰公子的博客-程序员宅基地

技术标签: # Qt  

/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Charts module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 or (at your option) any later version
** approved by the KDE Free Qt Foundation. The licenses are as published by
** the Free Software Foundation and appearing in the file LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include <QApplication>
#include <QMainWindow>
#include <QtCharts>
QT_USE_NAMESPACE

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

    //![1]
    QBarSet *set0 = new QBarSet("Jane");
    QBarSet *set1 = new QBarSet("John");
    QBarSet *set2 = new QBarSet("Axel");
    QBarSet *set3 = new QBarSet("Mary");
    QBarSet *set4 = new QBarSet("Samantha");

    *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;
    //![1]

    //![2]
    QBarSeries *series = new QBarSeries();
    series->append(set0);
    series->append(set1);
    series->append(set2);
    series->append(set3);
    series->append(set4);

    //![2]

    //![3]
    QChart *chart = new QChart();
    chart->addSeries(series);
    chart->setTitle("Simple barchart example");
    chart->setAnimationOptions(QChart::SeriesAnimations);
    //![3]

    //![4]
    QStringList categories;
    categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
    QBarCategoryAxis *axisX = new QBarCategoryAxis();
    axisX->append(categories);
    chart->addAxis(axisX, Qt::AlignBottom);
    series->attachAxis(axisX);

    QValueAxis *axisY = new QValueAxis();
    axisY->setRange(0,15);
    chart->addAxis(axisY, Qt::AlignLeft);
    series->attachAxis(axisY);
    //![4]

    //![5]
    chart->legend()->setVisible(true);
    chart->legend()->setAlignment(Qt::AlignBottom);
    //![5]

    //![6]
    QChartView *chartView = new QChartView(chart);
    chartView->setRenderHint(QPainter::Antialiasing);
    //![6]

    //![7]
    QMainWindow window;
    window.setCentralWidget(chartView);
    window.resize(420, 300);
    window.show();
    //![7]

    return a.exec();
}

运行效果图

 

 

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/nh5431313/article/details/109607523

智能推荐

Android JSON解析_H-lecter的博客-程序员宅基地

JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式。它基于JavaScript(Standard ECMA-262 3rd Edition - December 1999)的一个子集。 JSON采用完全独立于语言的文本格式,但是也使用了类似于C语言家族的习惯(包括C, C++, C#, Java, JavaScript, Perl, Python等)。这些

margin-top塌陷问题的现象与解决_FreeSpider公众号的博客-程序员宅基地

margin-top塌陷问题什么是margin-top塌陷margin-top塌陷是在CSS的盒子模型中出现的一种现象,描述的是当父元素包裹着一个子元素的时候,当给子元素设置margin-top属性时,此时只是想让子元素的边框距离父元素边框有一段距离,而却出现了父元素的顶端距离body这个边框出现了位移,这就是margin-top塌陷的现象。在未给子元素(绿色部分)添加margin-to...

单例模式中的readResolve()方法详解_单例模式 readresolve_keep one's resolveY的博客-程序员宅基地

resolve()方法 说到这个话题,我先抛出单例的饿汉式写法单例:饿汉式public class HungrySingleton { private HungrySingleton() { } private static final HungrySingleton hungry = new HungrySingleton(); public static HungrySingleton getInstance() { return hung

爬取58上的大量二手数据并保存在MongoDB中_Watch_dou的博客-程序员宅基地

爬取58二手分类商品的标题、价格、浏览情况等数据。from bs4 import BeautifulSoupimport requestsimport timeimport pymongoimport refrom numpy import *#####获取二手标签链接start_url = 'http://cs.58.com/sale.shtml'def get_chanel_url

QT TableView自定义委托_qt setitemdelegate_Sakuya__的博客-程序员宅基地

简述在经典的 MVC 模型中,view用于向用户展示 model 的数据。但是,Qt提供的不是 MVC 三层架构,而是一个 model/view 设计。这种设计并没有包含一个完整而独立的组件用于管理用户的交互。在这种结构中,为了获得对用户输入控制的灵活性,这种交互工作交给了delegate,也就是“委托”,去完成。简单来说,就像它们的名字一样,view 将用户输入委托给 delegate 处理...

流媒体 码率 Android 835,流媒体比特率与实际传输速率不同_weixin_39828457的博客-程序员宅基地

FPGA获取数据,并将它们放入TXT文件中。我正在测试从FIFO接口(32位)。虽然流光显示的比特率为180Mb/s,实际传输速率约为8Mb/s。这是显示比特率的流线型的C代码。公共不安全空隙XFEDATA(字节[]CBUFS,字节[]]XBUFS,字节[][OLAPS,ISO-PKtiOFIMP[]]PKTSHINFO){INT K=0;In LeN=0;成功率=0;故障=0;xFixBy数=0...

随便推点

如何在Outlook 2013中向安全发件人列表添加电子邮件地址_culingluan4376的博客-程序员宅基地

Do you find that your friends’ and relatives’ emails are getting sent to your Spam folder instead of your Inbox? Outlook provides a Safe Senders list that allows you to specify which email addresses a...

vue路由权限控制_灬风吹雨的博客-程序员宅基地

在路由.js文件中全局守卫router.beforeEach添加router.beforeEach((to, from, next) =&gt; { let access = [ //当前权限列表 ] if (canTurnTo(to.name, access, routes)){//routes当前路由列表 console.log("当前有权限") next() // 有权限,可访问 }else{ console.log("当前无权限") next()

Vue动态组件 & [email protected]的博客-程序员宅基地

前言在 vue 中,实现 Tab 切换主要有三种方式:使用动态组件,使用 vue-router 路由,使用第三方插件。本文将详细介绍Vue动态组件。所谓动态组件就是让多个组件使用同一个挂载点,并动态切换。一、is用法通过使用保留的&lt;component&gt;元素,动态地绑定到它的is特性,我们让多个组件可以使用同一个挂载点,并动态切换。根据v-bind:is="组件名" 中的组件名去自动匹配组件,如果匹配不到则不显示。改变挂载的组件,只需要修改is指令的值即可。【1.1...

Oracle/PLSQL: ORA-06550_weixin_30532987的博客-程序员宅基地

参考:http://blog.csdn.net/haiross/article/details/20612135Oracle/PLSQL: ORA-06550Learn the cause and how to resolve the ORA-06550 error message in Oracle.DescriptionWhen you encounter an ORA-06550 ...

C#试玩程序设计试题——定向越野(迷宫)_1021. 定向越野c++_GuestingNew的博客-程序员宅基地

问题描述:XX大学城离市中心比较远,因此占地面积巨大,因而XX市团委准备充分利用资源,在大学城举办定向越野比赛,但规则与普通定向越野不同,每个队被要求从某个起点出发最后到达终点,只要是地图上每个标注的点都可以走,经过一个点时必须在打卡器上打卡做记录,记录该点的打卡器所在位置的海拔高度,高度用一个非负整数来度量,该数将会被保存在卡中。最后到达终点时,该队的成绩就为卡中记录的最大数与最小数之差,差最..............................

Collaborative momentum: the author and the middle man in U.S. literature and culture Matthew 【翻译】_hongfu951的博客-程序员宅基地

Collaborative momentum: the author and themiddle man in U.S. literature and cultureMatthew Josef LavinUniversity of IowaCopyright 2012 Matthew J. LavinThis dissertation is available at Iowa Resea...

推荐文章

热门文章

相关标签