|
|
/****************************************************************************
|
|
|
**
|
|
|
** 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>
|
|
|
#include <QBarCategoryAxis>
|
|
|
#include <QLineSeries>
|
|
|
#include <QHorizontalBarSeries>
|
|
|
|
|
|
QTCOMMERCIALCHART_USE_NAMESPACE
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
{
|
|
|
QApplication a(argc, argv);
|
|
|
|
|
|
QLineSeries* series = new QLineSeries();
|
|
|
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();
|
|
|
QBarSeries* series2 = new QBarSeries();
|
|
|
series2->append(set0);
|
|
|
series2->append(set1);
|
|
|
series2->append(set2);
|
|
|
series2->append(set3);
|
|
|
series2->append(set4);
|
|
|
|
|
|
Chart* chart = new Chart();
|
|
|
// 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";
|
|
|
QBarCategoryAxis* axis = new QBarCategoryAxis();
|
|
|
axis->append(categories);
|
|
|
chart->setAxisX(axis, series2);
|
|
|
|
|
|
ChartView* chartView = new ChartView(chart);
|
|
|
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();
|
|
|
}
|
|
|
|