##// END OF EJS Templates
Adds barcategories axis to chartviewer
Michal Klocek -
r2122:1a63e7de0234
parent child
Show More
@@ -0,0 +1,65
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 "qbarseries.h"
24 #include "qbarset.h"
25 #include "qvalueaxis.h"
26 #include "qbarcategoryaxis.h"
27
28 class BarCategoryAxisX: public Chart
29 {
30 public:
31 QString name() { return "AxisX"; }
32 QString category() { return QObject::tr("Axis"); }
33 QString subCategory() { return "BarCategoryAxis"; }
34
35 QChart *createChart(const DataTable &table)
36 {
37 QChart *chart = new QChart();
38 chart->setTitle(" BarCateogry X , Value Y");
39
40 QString name("Series ");
41 QBarSeries *series = new QBarSeries(chart);
42 QValueAxis *valueaxis = new QValueAxis();
43 QBarCategoryAxis *barcategory = new QBarCategoryAxis();
44 for (int i(0); i < table.count(); i++) {
45 QBarSet *set = new QBarSet("Bar set " + QString::number(i));
46 foreach (Data data, table[i])
47 *set << data.first.y();
48 series->append(set);
49 }
50 chart->addSeries(series);
51
52 int count = series->barSets().first()->count();
53
54 for(int i =0 ; i < count ; i++){
55 barcategory->append(QString::number(i));
56 }
57
58 chart->setAxisY(valueaxis, series);
59 chart->setAxisX(barcategory, series);
60
61 return chart;
62 }
63 };
64
65 DECLARE_CHART(BarCategoryAxisX);
@@ -15,4 +15,5 SOURCES += \
15 pieseries/piechart.cpp \
15 pieseries/piechart.cpp \
16 pieseries/donutchart.cpp \
16 pieseries/donutchart.cpp \
17 axis/valueaxis.cpp \
17 axis/valueaxis.cpp \
18 axis/categoryaxis.cpp
18 axis/categoryaxis.cpp \
19 axis/barcategoryaxisx.cpp
General Comments 0
You need to be logged in to leave comments. Login now