##// END OF EJS Templates
Some perfs improvments....
Some perfs improvments. Fixed bug on update outside of data range. Signed-off-by: jeandet <alexis.jeandet@member.fsf.org>

File last commit:

r2854:46147b040d06
r2902:1f7564788f9d 5.7
Show More
main.cpp
120 lines | 3.6 KiB | text/x-c | CppLexer
Miikka Heikkinen
Updated license...
r2854 /****************************************************************************
sauimone
added example to combine line and barchart
r1632 **
Miikka Heikkinen
Updated license...
r2854 ** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
sauimone
added example to combine line and barchart
r1632 **
Miikka Heikkinen
Updated license...
r2854 ** This file is part of the Qt Charts module of the Qt Toolkit.
sauimone
added example to combine line and barchart
r1632 **
Miikka Heikkinen
Updated license...
r2854 ** $QT_BEGIN_LICENSE:GPL$
Titta Heikkala
Updated license headers...
r2845 ** 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
Miikka Heikkinen
Updated license...
r2854 ** 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.
sauimone
added example to combine line and barchart
r1632 **
Titta Heikkala
Updated license headers...
r2845 ** $QT_END_LICENSE$
**
Miikka Heikkinen
Updated license...
r2854 ****************************************************************************/
sauimone
added example to combine line and barchart
r1632
Titta Heikkala
Fix include syntax...
r2714 #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>
sauimone
added example to combine line and barchart
r1632
Titta Heikkala
Qt Charts project file structure change...
r2712 QT_CHARTS_USE_NAMESPACE
sauimone
added example to combine line and barchart
r1632
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");
Tero Ahola
Line and bar example now has a name for the line
r2342 QBarSet *set4 = new QBarSet("Sam");
sauimone
added example to combine line and barchart
r1632
*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]
Jani Honkonen
more coding style fixes for examples...
r2102 QBarSeries *barseries = new QBarSeries();
sauimone
added example to combine line and barchart
r1632 barseries->append(set0);
barseries->append(set1);
barseries->append(set2);
barseries->append(set3);
barseries->append(set4);
//![2]
//![8]
Jani Honkonen
more coding style fixes for examples...
r2102 QLineSeries *lineseries = new QLineSeries();
Tero Ahola
Line and bar example now has a name for the line
r2342 lineseries->setName("trend");
Jani Honkonen
coding style fixes for examples
r2098 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));
sauimone
added example to combine line and barchart
r1632 //![8]
//![3]
Jani Honkonen
more coding style fixes for examples...
r2102 QChart *chart = new QChart();
sauimone
added example to combine line and barchart
r1632 chart->addSeries(barseries);
chart->addSeries(lineseries);
chart->setTitle("Line and barchart example");
//![3]
//![4]
QStringList categories;
categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
Jani Honkonen
more coding style fixes for examples...
r2102 QBarCategoryAxis *axisX = new QBarCategoryAxis();
sauimone
added example to combine line and barchart
r1632 axisX->append(categories);
Jani Honkonen
coding style fixes for examples
r2098 chart->setAxisX(axisX, lineseries);
chart->setAxisX(axisX, barseries);
axisX->setRange(QString("Jan"), QString("Jun"));
sauimone
added example to combine line and barchart
r1632
Jani Honkonen
more coding style fixes for examples...
r2102 QValueAxis *axisY = new QValueAxis();
Jani Honkonen
coding style fixes for examples
r2098 chart->setAxisY(axisY, lineseries);
chart->setAxisY(axisY, barseries);
axisY->setRange(0, 20);
sauimone
added example to combine line and barchart
r1632 //![4]
//![5]
chart->legend()->setVisible(true);
chart->legend()->setAlignment(Qt::AlignBottom);
//![5]
//![6]
Jani Honkonen
more coding style fixes for examples...
r2102 QChartView *chartView = new QChartView(chart);
sauimone
added example to combine line and barchart
r1632 chartView->setRenderHint(QPainter::Antialiasing);
//![6]
//![7]
QMainWindow window;
window.setCentralWidget(chartView);
Titta Heikkala
Fix the geometry for examples and demos...
r2647 window.resize(440, 300);
sauimone
added example to combine line and barchart
r1632 window.show();
//![7]
return a.exec();
}