##// END OF EJS Templates
Added colormap chart examples...
Added colormap chart examples Improved Zoom, added direction parameter. Signed-off-by: jeandet <alexis.jeandet@member.fsf.org>

File last commit:

r2854:46147b040d06
r2901:d2a7a7849617
Show More
main.cpp
109 lines | 3.5 KiB | text/x-c | CppLexer
Miikka Heikkinen
Updated license...
r2854 /****************************************************************************
Marek Rosa
Added DateTimeAxis Example
r1739 **
Miikka Heikkinen
Updated license...
r2854 ** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
Marek Rosa
Added DateTimeAxis Example
r1739 **
Miikka Heikkinen
Updated license...
r2854 ** This file is part of the Qt Charts module of the Qt Toolkit.
Marek Rosa
Added DateTimeAxis Example
r1739 **
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.
Marek Rosa
Added DateTimeAxis Example
r1739 **
Titta Heikkala
Updated license headers...
r2845 ** $QT_END_LICENSE$
**
Miikka Heikkinen
Updated license...
r2854 ****************************************************************************/
Marek Rosa
Added DateTimeAxis Example
r1739
Titta Heikkala
Fix include syntax...
r2714 #include <QtWidgets/QApplication>
#include <QtWidgets/QMainWindow>
#include <QtCharts/QChartView>
#include <QtCharts/QLineSeries>
#include <QtCore/QDateTime>
#include <QtCharts/QDateTimeAxis>
#include <QtCore/QFile>
#include <QtCore/QTextStream>
#include <QtCore/QDebug>
#include <QtCharts/QValueAxis>
Marek Rosa
Added DateTimeAxis Example
r1739
Titta Heikkala
Qt Charts project file structure change...
r2712 QT_CHARTS_USE_NAMESPACE
Marek Rosa
Added DateTimeAxis Example
r1739
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Jani Honkonen
coding style fixes for examples
r2098 qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
Marek Rosa
Added DateTimeAxis Example
r1739
//![1]
Jani Honkonen
more coding style fixes for examples...
r2102 QLineSeries *series = new QLineSeries();
Marek Rosa
Added DateTimeAxis Example
r1739 //![1]
//![2]
Marek Rosa
Update datetimeaxis example
r1931 // data from http://www.swpc.noaa.gov/ftpdir/weekly/RecentIndices.txt
Marek Rosa
datetimeaxis example documented
r1986 // http://www.swpc.noaa.gov/ftpdir/weekly/README
// http://www.weather.gov/disclaimer
Marek Rosa
Update datetimeaxis example
r1931 QFile sunSpots(":sun");
if (!sunSpots.open(QIODevice::ReadOnly | QIODevice::Text)) {
return 1;
Marek Rosa
Added DateTimeAxis Example
r1739 }
Marek Rosa
Update datetimeaxis example
r1931
QTextStream stream(&sunSpots);
while (!stream.atEnd()) {
QString line = stream.readLine();
if (line.startsWith("#") || line.startsWith(":"))
continue;
Marek Rosa
QCategoryAxis: fix to grid lines drawing
r1938 QStringList values = line.split(" ", QString::SkipEmptyParts);
Marek Rosa
Update datetimeaxis example
r1931 QDateTime momentInTime;
Marek Rosa
QCategoryAxis: fix to grid lines drawing
r1938 momentInTime.setDate(QDate(values[0].toInt(), values[1].toInt() , 15));
series->append(momentInTime.toMSecsSinceEpoch(), values[2].toDouble());
Marek Rosa
Update datetimeaxis example
r1931 }
sunSpots.close();
Marek Rosa
Added DateTimeAxis Example
r1739 //![2]
//![3]
Jani Honkonen
more coding style fixes for examples...
r2102 QChart *chart = new QChart();
Marek Rosa
Added DateTimeAxis Example
r1739 chart->addSeries(series);
Marek Rosa
datetimeaxis example documented
r1986 chart->legend()->hide();
chart->setTitle("Sunspots count (by Space Weather Prediction Center)");
//![3]
//![4]
Marek Rosa
Added DateTimeAxis Example
r1739 QDateTimeAxis *axisX = new QDateTimeAxis;
Marek Rosa
Update datetimeaxis example
r1931 axisX->setTickCount(10);
axisX->setFormat("MMM yyyy");
Michal Klocek
Refactors internals...
r2273 axisX->setTitleText("Date");
Marek Rosa
datetimeaxis example vertical axis format set to integers
r2332 chart->addAxis(axisX, Qt::AlignBottom);
series->attachAxis(axisX);
QValueAxis *axisY = new QValueAxis;
axisY->setLabelFormat("%i");
axisY->setTitleText("Sunspots count");
chart->addAxis(axisY, Qt::AlignLeft);
series->attachAxis(axisY);
Marek Rosa
Added DateTimeAxis Example
r1739 //![4]
Marek Rosa
datetimeaxis example documented
r1986
//![5]
Jani Honkonen
more coding style fixes for examples...
r2102 QChartView *chartView = new QChartView(chart);
Marek Rosa
Added DateTimeAxis Example
r1739 chartView->setRenderHint(QPainter::Antialiasing);
//![5]
Marek Rosa
datetimeaxis example documented
r1986
//![6]
Marek Rosa
Added DateTimeAxis Example
r1739 QMainWindow window;
window.setCentralWidget(chartView);
Titta Heikkala
Fix the geometry for examples and demos...
r2647 window.resize(820, 600);
Marek Rosa
Added DateTimeAxis Example
r1739 window.show();
Marek Rosa
datetimeaxis example documented
r1986 //![6]
Marek Rosa
Added DateTimeAxis Example
r1739
return a.exec();
}