##// END OF EJS Templates
Line and bar example now has a name for the line
Tero Ahola -
r2342:098ca1392d78
parent child
Show More
1 NO CONTENT: modified file, binary diff hidden
@@ -1,111 +1,111
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 <QLineSeries>
27 27 #include <QLegend>
28 28 #include <QBarCategoryAxis>
29 29 #include <QValueAxis>
30 30
31 31 QTCOMMERCIALCHART_USE_NAMESPACE
32 32
33 33 int main(int argc, char *argv[])
34 34 {
35 35 QApplication a(argc, argv);
36 36
37 37 //![1]
38 38 QBarSet *set0 = new QBarSet("Jane");
39 39 QBarSet *set1 = new QBarSet("John");
40 40 QBarSet *set2 = new QBarSet("Axel");
41 41 QBarSet *set3 = new QBarSet("Mary");
42 QBarSet *set4 = new QBarSet("Samantha");
42 QBarSet *set4 = new QBarSet("Sam");
43 43
44 44 *set0 << 1 << 2 << 3 << 4 << 5 << 6;
45 45 *set1 << 5 << 0 << 0 << 4 << 0 << 7;
46 46 *set2 << 3 << 5 << 8 << 13 << 8 << 5;
47 47 *set3 << 5 << 6 << 7 << 3 << 4 << 5;
48 48 *set4 << 9 << 7 << 5 << 3 << 1 << 2;
49 49 //![1]
50 50
51 51 //![2]
52 52 QBarSeries *barseries = new QBarSeries();
53 53 barseries->append(set0);
54 54 barseries->append(set1);
55 55 barseries->append(set2);
56 56 barseries->append(set3);
57 57 barseries->append(set4);
58 58 //![2]
59 59
60 60 //![8]
61 61 QLineSeries *lineseries = new QLineSeries();
62
62 lineseries->setName("trend");
63 63 lineseries->append(QPoint(0, 4));
64 64 lineseries->append(QPoint(1, 15));
65 65 lineseries->append(QPoint(2, 20));
66 66 lineseries->append(QPoint(3, 4));
67 67 lineseries->append(QPoint(4, 12));
68 68 lineseries->append(QPoint(5, 17));
69 69 //![8]
70 70
71 71 //![3]
72 72 QChart *chart = new QChart();
73 73 chart->addSeries(barseries);
74 74 chart->addSeries(lineseries);
75 75 chart->setTitle("Line and barchart example");
76 76 //![3]
77 77
78 78 //![4]
79 79 QStringList categories;
80 80 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
81 81 QBarCategoryAxis *axisX = new QBarCategoryAxis();
82 82 axisX->append(categories);
83 83 chart->setAxisX(axisX, lineseries);
84 84 chart->setAxisX(axisX, barseries);
85 85 axisX->setRange(QString("Jan"), QString("Jun"));
86 86
87 87 QValueAxis *axisY = new QValueAxis();
88 88 chart->setAxisY(axisY, lineseries);
89 89 chart->setAxisY(axisY, barseries);
90 90 axisY->setRange(0, 20);
91 91 //![4]
92 92
93 93 //![5]
94 94 chart->legend()->setVisible(true);
95 95 chart->legend()->setAlignment(Qt::AlignBottom);
96 96 //![5]
97 97
98 98 //![6]
99 99 QChartView *chartView = new QChartView(chart);
100 100 chartView->setRenderHint(QPainter::Antialiasing);
101 101 //![6]
102 102
103 103 //![7]
104 104 QMainWindow window;
105 105 window.setCentralWidget(chartView);
106 106 window.resize(400, 300);
107 107 window.show();
108 108 //![7]
109 109
110 110 return a.exec();
111 111 }
General Comments 0
You need to be logged in to leave comments. Login now