##// END OF EJS Templates
horizontal percent barchart example update
sauimone -
r1689:4238867b377c
parent child
Show More
@@ -1,95 +1,95
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include <QApplication>
22 22 #include <QMainWindow>
23 23 #include <QChartView>
24 24 #include <QBarSeries>
25 25 #include <QBarSet>
26 26 #include <QLegend>
27 27 #include <QBarCategoriesAxis>
28 28 #include <QHorizontalPercentBarSeries>
29 29
30 30 QTCOMMERCIALCHART_USE_NAMESPACE
31 31
32 32 int main(int argc, char *argv[])
33 33 {
34 34 QApplication a(argc, argv);
35 35
36 36 //![1]
37 37 QBarSet *set0 = new QBarSet("Jane");
38 38 QBarSet *set1 = new QBarSet("John");
39 39 QBarSet *set2 = new QBarSet("Axel");
40 40 QBarSet *set3 = new QBarSet("Mary");
41 41 QBarSet *set4 = new QBarSet("Samantha");
42 42
43 43 *set0 << 1 << 2 << 3 << 4 << 5 << 6;
44 44 *set1 << 5 << 0 << 0 << 4 << 0 << 7;
45 45 *set2 << 3 << 5 << 8 << 13 << 8 << 5;
46 46 *set3 << 5 << 6 << 7 << 3 << 4 << 5;
47 47 *set4 << 9 << 7 << 5 << 3 << 1 << 2;
48 48 //![1]
49 49
50 50 //![2]
51 51 QHorizontalPercentBarSeries *series = new QHorizontalPercentBarSeries();
52 52 series->append(set0);
53 53 series->append(set1);
54 54 series->append(set2);
55 55 series->append(set3);
56 56 series->append(set4);
57 57
58 58 //![2]
59 59
60 60 //![3]
61 61 QChart* chart = new QChart();
62 62 chart->addSeries(series);
63 chart->setTitle("Simple horizontal stacked barchart example");
63 chart->setTitle("Simple horizontal percent barchart example");
64 64 chart->createDefaultAxes();
65 65 chart->setAnimationOptions(QChart::SeriesAnimations);
66 66 //![3]
67 67
68 68 //![4]
69 69 QStringList categories;
70 70 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
71 71 QBarCategoriesAxis* axis = new QBarCategoriesAxis();
72 72 axis->append(categories);
73 73 chart->createDefaultAxes();
74 74 chart->setAxisY(axis,series);
75 75 //![4]
76 76
77 77 //![5]
78 78 chart->legend()->setVisible(true);
79 79 chart->legend()->setAlignment(Qt::AlignBottom);
80 80 //![5]
81 81
82 82 //![6]
83 83 QChartView* chartView = new QChartView(chart);
84 84 chartView->setRenderHint(QPainter::Antialiasing);
85 85 //![6]
86 86
87 87 //![7]
88 88 QMainWindow window;
89 89 window.setCentralWidget(chartView);
90 90 window.resize(400, 300);
91 91 window.show();
92 92 //![7]
93 93
94 94 return a.exec();
95 95 }
General Comments 0
You need to be logged in to leave comments. Login now