main.cpp
103 lines
| 2.8 KiB
| text/x-c
|
CppLexer
|
r830 | /**************************************************************************** | ||
** | ||||
** 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$ | ||||
** | ||||
****************************************************************************/ | ||||
|
r317 | #include <QtGui/QApplication> | ||
#include <QMainWindow> | ||||
#include <qchartglobal.h> | ||||
#include <qchartview.h> | ||||
|
r349 | #include <qlineseries.h> | ||
|
r321 | #include <qscatterseries.h> | ||
|
r338 | #include <qbarseries.h> | ||
|
r321 | #include <qbarset.h> | ||
#include <qpieseries.h> | ||||
|
r377 | #include <QStringList> | ||
|
r317 | |||
QTCOMMERCIALCHART_USE_NAMESPACE | ||||
int main(int argc, char *argv[]) | ||||
{ | ||||
QApplication a(argc, argv); | ||||
//! [1] | ||||
// Create chart view | ||||
QChartView *chartView = new QChartView(); | ||||
|
r334 | chartView->setRenderHint(QPainter::Antialiasing); | ||
|
r343 | chartView->setChartTitle("Simple Line Chart"); | ||
|
r321 | // Add series to the chart | ||
|
r349 | QLineSeries *line = new QLineSeries(); | ||
|
r796 | line->append(0.0, 0.8); | ||
line->append(1.1, 1.1); | ||||
line->append(2.0, 2.5); | ||||
|
r321 | chartView->addSeries(line); | ||
|
r317 | //! [1] | ||
|
r343 | chartView->setChartTitle("\'Scietific\' theme"); | ||
|
r317 | //! [2] | ||
|
r321 | // Change theme | ||
|
r757 | chartView->setChartTheme(QChart::ChartThemeHighContrast); | ||
|
r317 | //! [2] | ||
|
r343 | chartView->setChartTitle("Simple Pie Chart"); | ||
|
r317 | //! [3] | ||
|
r321 | // Add pie series | ||
|
r334 | // ... | ||
|
r321 | QPieSeries *pie = new QPieSeries(); | ||
|
r796 | pie->append(3.4, "slice1"); | ||
pie->append(6.7, "slice2"); | ||||
|
r321 | chartView->addSeries(pie); | ||
|
r317 | //! [3] | ||
|
r343 | chartView->setChartTitle("Simple Scatter Chart"); | ||
|
r321 | //! [4] | ||
// Add scatter series | ||||
|
r334 | // ... | ||
|
r321 | QScatterSeries *scatter = new QScatterSeries(); | ||
for (qreal x(0); x < 100; x += 0.5) { | ||||
qreal y = rand() % 100; | ||||
*(scatter) << QPointF(x, y); | ||||
} | ||||
chartView->addSeries(scatter); | ||||
//! [4] | ||||
|
r343 | chartView->setChartTitle("Simple Bar Chart"); | ||
|
r321 | //! [5] | ||
|
r334 | // ... | ||
|
r321 | // Add bar series | ||
|
r377 | QStringList barCategory; | ||
barCategory << "Jan" | ||||
|
r321 | << "Feb" | ||
<< "Mar"; | ||||
|
r338 | QBarSeries *bar = new QBarSeries(barCategory); | ||
|
r321 | QBarSet *barSet = new QBarSet("Sales"); | ||
*barSet << 123.2 | ||||
<< 301.3 | ||||
<< 285.8; | ||||
bar->addBarSet(barSet); | ||||
chartView->addSeries(bar); | ||||
//! [5] | ||||
|
r317 | QMainWindow w; | ||
|
r343 | w.resize(400, 300); | ||
|
r317 | w.setCentralWidget(chartView); | ||
|
r343 | w.setWindowFlags(Qt::FramelessWindowHint); | ||
|
r317 | w.show(); | ||
return a.exec(); | ||||
} | ||||