main.cpp
89 lines
| 2.7 KiB
| text/x-c
|
CppLexer
Michal Klocek
|
r1722 | /**************************************************************************** | ||
** | ||||
** Copyright (C) 2012 Digia Plc | ||||
** All rights reserved. | ||||
** For any questions to Digia, please use contact form at http://qt.digia.com | ||||
** | ||||
** This file is part of the Qt Commercial Charts Add-on. | ||||
** | ||||
** $QT_BEGIN_LICENSE$ | ||||
** Licensees holding valid Qt Commercial licenses may use this file in | ||||
** accordance with the Qt Commercial License Agreement provided with the | ||||
** Software or, alternatively, in accordance with the terms contained in | ||||
** a written agreement between you and Digia. | ||||
** | ||||
** If you have questions regarding the use of this file, please use | ||||
** contact form at http://qt.digia.com | ||||
** $QT_END_LICENSE$ | ||||
** | ||||
****************************************************************************/ | ||||
#include "chart.h" | ||||
#include "chartview.h" | ||||
#include <QApplication> | ||||
#include <QMainWindow> | ||||
#include <qmath.h> | ||||
#include <QBarSeries> | ||||
#include <QBarSet> | ||||
Marek Rosa
|
r1809 | #include <QBarCategoryAxis> | ||
Michal Klocek
|
r1722 | #include <QLineSeries> | ||
#include <QHorizontalBarSeries> | ||||
QTCOMMERCIALCHART_USE_NAMESPACE | ||||
int main(int argc, char *argv[]) | ||||
{ | ||||
QApplication a(argc, argv); | ||||
Jani Honkonen
|
r2102 | QLineSeries *series = new QLineSeries(); | ||
Michal Klocek
|
r1722 | for (int i = 0; i < 500; i++) { | ||
QPointF p((qreal) i, qSin(M_PI / 50 * i) * 100); | ||||
p.ry() += qrand() % 20; | ||||
*series << p; | ||||
} | ||||
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; | ||||
//QHorizontalBarSeries* series2 = new QHorizontalBarSeries(); | ||||
Jani Honkonen
|
r2102 | QBarSeries *series2 = new QBarSeries(); | ||
Michal Klocek
|
r1722 | series2->append(set0); | ||
series2->append(set1); | ||||
series2->append(set2); | ||||
series2->append(set3); | ||||
series2->append(set4); | ||||
Jani Honkonen
|
r2102 | Chart *chart = new Chart(); | ||
Michal Klocek
|
r1722 | // chart->addSeries(series); | ||
chart->addSeries(series2); | ||||
chart->setTitle("Scroll in/out example"); | ||||
chart->legend()->hide(); | ||||
chart->createDefaultAxes(); | ||||
QStringList categories; | ||||
categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; | ||||
Jani Honkonen
|
r2102 | QBarCategoryAxis *axis = new QBarCategoryAxis(); | ||
Michal Klocek
|
r1722 | axis->append(categories); | ||
chart->setAxisX(axis, series2); | ||||
Jani Honkonen
|
r2102 | ChartView *chartView = new ChartView(chart); | ||
Michal Klocek
|
r1722 | chartView->setRenderHint(QPainter::Antialiasing); | ||
QMainWindow window; | ||||
window.setCentralWidget(chartView); | ||||
window.resize(400, 300); | ||||
window.grabGesture(Qt::PanGesture); | ||||
window.grabGesture(Qt::PinchGesture); | ||||
window.show(); | ||||
return a.exec(); | ||||
} | ||||