@@ -0,0 +1,83 | |||
|
1 | /**************************************************************************** | |
|
2 | ** | |
|
3 | ** Copyright (C) 2012 Digia Plc | |
|
4 | ** All rights reserved. | |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
|
6 | ** | |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
|
8 | ** | |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
14 | ** | |
|
15 | ** If you have questions regarding the use of this file, please use | |
|
16 | ** contact form at http://qt.digia.com | |
|
17 | ** $QT_END_LICENSE$ | |
|
18 | ** | |
|
19 | ****************************************************************************/ | |
|
20 | ||
|
21 | #include "charts.h" | |
|
22 | #include "qchart.h" | |
|
23 | #include "qlineseries.h" | |
|
24 | #include "qvalueaxis.h" | |
|
25 | #include "qcategoryaxis.h" | |
|
26 | ||
|
27 | class MultiValueAxis: public Chart | |
|
28 | { | |
|
29 | public: | |
|
30 | QString name() | |
|
31 | { | |
|
32 | return "MultiValueAxis"; | |
|
33 | } | |
|
34 | QString category() | |
|
35 | { | |
|
36 | return QObject::tr("Axis"); | |
|
37 | } | |
|
38 | QString subCategory() | |
|
39 | { | |
|
40 | return QString::null; | |
|
41 | } | |
|
42 | ||
|
43 | QChart *createChart(const DataTable &table) | |
|
44 | { | |
|
45 | QChart *chart = new QChart(); | |
|
46 | QValueAxis *axisX; | |
|
47 | QValueAxis *axisY; | |
|
48 | ||
|
49 | chart->setTitle("MultiValueAxis"); | |
|
50 | ||
|
51 | QString name("Series"); | |
|
52 | int nameIndex = 0; | |
|
53 | foreach (DataList list, table) { | |
|
54 | QLineSeries *series = new QLineSeries(chart); | |
|
55 | foreach (Data data, list) | |
|
56 | series->append(data.first); | |
|
57 | series->setName(name + QString::number(nameIndex)); | |
|
58 | ||
|
59 | chart->addSeries(series); | |
|
60 | axisX = new QValueAxis(); | |
|
61 | axisX->setLinePenColor(series->pen().color()); | |
|
62 | if (nameIndex % 2) | |
|
63 | axisX->setAlignment(Qt::AlignTop); | |
|
64 | else | |
|
65 | axisX->setAlignment(Qt::AlignBottom); | |
|
66 | axisY = new QValueAxis(); | |
|
67 | axisY->setLinePenColor(series->pen().color()); | |
|
68 | ||
|
69 | if (nameIndex % 2) | |
|
70 | axisY->setAlignment(Qt::AlignRight); | |
|
71 | else | |
|
72 | axisY->setAlignment(Qt::AlignLeft); | |
|
73 | ||
|
74 | chart->setAxisX(axisX, series); | |
|
75 | chart->setAxisY(axisY, series); | |
|
76 | nameIndex++; | |
|
77 | } | |
|
78 | ||
|
79 | return chart; | |
|
80 | } | |
|
81 | }; | |
|
82 | ||
|
83 | DECLARE_CHART(MultiValueAxis); |
General Comments 0
You need to be logged in to leave comments.
Login now