main.cpp
83 lines
| 2.4 KiB
| text/x-c
|
CppLexer
|
r101 | #include <QApplication> | ||
#include <QMainWindow> | ||||
#include <QStandardItemModel> | ||||
|
r338 | #include <qpercentbarseries.h> | ||
|
r276 | #include <qchartview.h> | ||
|
r296 | #include <qbarset.h> | ||
|
r387 | #include <qchartaxis.h> | ||
|
r377 | #include <QStringList> | ||
|
r101 | |||
QTCOMMERCIALCHART_USE_NAMESPACE | ||||
int main(int argc, char *argv[]) | ||||
{ | ||||
QApplication a(argc, argv); | ||||
QMainWindow window; | ||||
|
r325 | //! [1] | ||
|
r377 | // Define categories | ||
QStringList categories; | ||||
|
r387 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; | ||
|
r319 | //! [1] | ||
|
r170 | |||
|
r325 | //! [2] | ||
// Create some test sets for chat | ||||
|
r296 | QBarSet *set0 = new QBarSet("Bub"); | ||
QBarSet *set1 = new QBarSet("Bob"); | ||||
QBarSet *set2 = new QBarSet("Guybrush"); | ||||
QBarSet *set3 = new QBarSet("Larry"); | ||||
QBarSet *set4 = new QBarSet("Zak"); | ||||
|
r101 | |||
|
r387 | *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; | ||||
|
r325 | //! [2] | ||
//! [3] | ||||
// Create series and add sets to it | ||||
|
r377 | QPercentBarSeries* series = new QPercentBarSeries(categories); | ||
|
r173 | |||
|
r276 | series->addBarSet(set0); | ||
series->addBarSet(set1); | ||||
series->addBarSet(set2); | ||||
series->addBarSet(set3); | ||||
series->addBarSet(set4); | ||||
|
r325 | //! [3] | ||
|
r169 | |||
|
r325 | //! [4] | ||
|
r425 | // Enable tooltip | ||
|
r357 | series->setToolTipEnabled(); | ||
|
r425 | |||
// Connect clicked signal of set to toggle floating values of set. | ||||
// Note that we leave QBarset "Zak" unconnected here, so clicking on it doesn't toggle values. | ||||
QObject::connect(set0,SIGNAL(clicked(QString)),set0,SIGNAL(toggleFloatingValues())); | ||||
QObject::connect(set1,SIGNAL(clicked(QString)),set1,SIGNAL(toggleFloatingValues())); | ||||
QObject::connect(set2,SIGNAL(clicked(QString)),set2,SIGNAL(toggleFloatingValues())); | ||||
QObject::connect(set3,SIGNAL(clicked(QString)),set3,SIGNAL(toggleFloatingValues())); | ||||
|
r512 | QObject::connect(set4,SIGNAL(clicked(QString)),set4,SIGNAL(toggleFloatingValues())); | ||
|
r325 | //! [4] | ||
//! [5] | ||||
// Create view for chart and add series to it. Apply theme. | ||||
|
r296 | |||
|
r276 | QChartView* chartView = new QChartView(&window); | ||
chartView->addSeries(series); | ||||
chartView->setChartTitle("simple percent barchart"); | ||||
chartView->setChartTheme(QChart::ChartThemeIcy); | ||||
|
r325 | //! [5] | ||
|
r101 | |||
|
r387 | //! [6] | ||
|
r679 | //chartView->axisX()->setAxisVisible(false); | ||
|
r535 | chartView->axisX()->setGridLineVisible(false); | ||
|
r387 | chartView->axisX()->setLabelsVisible(false); | ||
//! [6] | ||||
|
r276 | window.setCentralWidget(chartView); | ||
|
r101 | window.resize(400, 300); | ||
window.show(); | ||||
return a.exec(); | ||||
} | ||||