##// END OF EJS Templates
categorylinechart in chartviewer tweaked
Marek Rosa -
r1976:9231f93419e5
parent child
Show More
@@ -1,70 +1,70
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "charts.h"
21 #include "charts.h"
22 #include "qchart.h"
22 #include "qchart.h"
23 #include "qlineseries.h"
23 #include "qlineseries.h"
24 #include <QCategoryAxis>
24 #include <QCategoryAxis>
25
25
26 class CategoryLineChart: public Chart
26 class CategoryLineChart: public Chart
27 {
27 {
28 public:
28 public:
29 QString name() { return QObject::tr("CategoryLineChart"); }
29 QString name() { return QObject::tr("CategoryLineChart"); }
30 QString category() { return QObject::tr("XYSeries"); }
30 QString category() { return QObject::tr("XYSeries"); }
31 QString subCategory() { return QString::null; }
31 QString subCategory() { return QString::null; }
32
32
33 QChart* createChart(const DataTable& table) {
33 QChart* createChart(const DataTable& table) {
34
34
35 QChart* chart = new QChart();
35 QChart* chart = new QChart();
36 chart->setTitle("Category Line chart");
36 chart->setTitle("Category Line chart");
37
37
38 QString name("Series ");
38 QString name("Series ");
39 int nameIndex = 0;
39 int nameIndex = 0;
40 foreach (DataList list, table) {
40 foreach (DataList list, table) {
41 QLineSeries *series = new QLineSeries(chart);
41 QLineSeries *series = new QLineSeries(chart);
42 foreach (Data data, list)
42 foreach (Data data, list)
43 series->append(data.first);
43 series->append(data.first);
44 series->setName(name + QString::number(nameIndex));
44 series->setName(name + QString::number(nameIndex));
45 nameIndex++;
45 nameIndex++;
46 chart->addSeries(series);
46 chart->addSeries(series);
47 }
47 }
48
48
49 // chart->createDefaultAxes();
49 // chart->createDefaultAxes();
50 QCategoryAxis *axisX = new QCategoryAxis;
50 QCategoryAxis *axisX = new QCategoryAxis;
51 axisX->append("low", 5);
51 axisX->append("low", 5);
52 axisX->append("optimal", 12);
52 axisX->append("avg.", 12);
53 axisX->append("high", 19);
53 axisX->append("high", 19);
54 axisX->setRange(-1, 20);
54 axisX->setRange(0, 20);
55 chart->setAxisX(axisX, chart->series().at(0));
55 chart->setAxisX(axisX, chart->series().at(0));
56
56
57 QCategoryAxis *axisY = new QCategoryAxis;
57 QCategoryAxis *axisY = new QCategoryAxis;
58 axisY->append("low", 5);
58 axisY->append("cheap", 5);
59 axisY->append("optimal", 8);
59 axisY->append("fair", 12);
60 axisY->append("high", 12);
60 axisY->append("pricy", 20);
61 axisY->setRange(-5, 20);
61 axisY->setRange(0, 20);
62 chart->setAxisY(axisY, chart->series().at(0));
62 chart->setAxisY(axisY, chart->series().at(0));
63
63
64 return chart;
64 return chart;
65 }
65 }
66
66
67 };
67 };
68
68
69 DECLARE_CHART(CategoryLineChart)
69 DECLARE_CHART(CategoryLineChart)
70
70
General Comments 0
You need to be logged in to leave comments. Login now