|
1 | NO CONTENT: new file 100644, binary diff hidden |
@@ -0,0 +1,30 | |||
|
1 | /*! | |
|
2 | \example example/areachart | |
|
3 | \title AreaChart Example | |
|
4 | \subtitle | |
|
5 | ||
|
6 | The example shows how to create simple area chart. | |
|
7 | ||
|
8 | \image areachart.png | |
|
9 | ||
|
10 | To create area charts, we need two QLineSeries instances. They are going to define upper and lower boundary of the area. | |
|
11 | ||
|
12 | \snippet ../example/areachart/main.cpp 1 | |
|
13 | ||
|
14 | We add data to both series, we use stream operator. | |
|
15 | ||
|
16 | \snippet ../example/areachart/main.cpp 2 | |
|
17 | ||
|
18 | Now we create QAreaSeries instance using two line series objects. We set the custom gradient fill and width of the outline. | |
|
19 | ||
|
20 | \snippet ../example/areachart/main.cpp 3 | |
|
21 | ||
|
22 | In the end we create QChartView instance, set title, set anti-aliasing and add area series. We also set the specific range for axes. | |
|
23 | ||
|
24 | \snippet ../example/areachart/main.cpp 4 | |
|
25 | ||
|
26 | Chart is ready to be shown. | |
|
27 | ||
|
28 | \snippet ../example/areachart/main.cpp 5 | |
|
29 | ||
|
30 | */ No newline at end of file |
@@ -0,0 +1,8 | |||
|
1 | !include( ../example.pri ) { | |
|
2 | error( "Couldn't find the example.pri file!" ) | |
|
3 | } | |
|
4 | TARGET = areachart | |
|
5 | SOURCES += main.cpp | |
|
6 | ||
|
7 | ||
|
8 |
@@ -0,0 +1,59 | |||
|
1 | #include <QApplication> | |
|
2 | #include <QMainWindow> | |
|
3 | #include <qchartview.h> | |
|
4 | #include <qlineseries.h> | |
|
5 | #include <qareaseries.h> | |
|
6 | #include <qchart.h> | |
|
7 | #include <qchartaxis.h> | |
|
8 | #include <cmath> | |
|
9 | ||
|
10 | QTCOMMERCIALCHART_USE_NAMESPACE | |
|
11 | ||
|
12 | int main(int argc, char *argv[]) | |
|
13 | { | |
|
14 | QApplication a(argc, argv); | |
|
15 | ||
|
16 | //![1] | |
|
17 | ||
|
18 | QLineSeries* series0 = new QLineSeries(); | |
|
19 | QLineSeries* series1 = new QLineSeries(); | |
|
20 | ||
|
21 | //![1] | |
|
22 | ||
|
23 | //![2] | |
|
24 | *series0 << QPointF(1, 5) << QPointF(3, 7) << QPointF(7, 6) << QPointF(9, 7) << QPointF(12,6)<<QPointF(16,7)<<QPointF(18,5); | |
|
25 | *series1 << QPointF(1, 3) << QPointF(3, 4) << QPointF(7, 3) << QPointF(8, 2) << QPointF(12,3)<<QPointF(16,4)<<QPointF(18,3); | |
|
26 | //![2] | |
|
27 | //![3] | |
|
28 | ||
|
29 | QAreaSeries* series = new QAreaSeries(series0,series1); | |
|
30 | QPen pen(0x059605); | |
|
31 | pen.setWidth(3); | |
|
32 | series->setPen(pen); | |
|
33 | ||
|
34 | QLinearGradient gradient(QPointF(0, 0), QPointF(0, 1)); | |
|
35 | gradient.setColorAt(0.0,0x3cc63c); | |
|
36 | gradient.setColorAt(1.0, 0x26f626); | |
|
37 | gradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
|
38 | series->setBrush(gradient); | |
|
39 | ||
|
40 | //![3] | |
|
41 | //![4] | |
|
42 | QMainWindow window; | |
|
43 | QChartView* chartView = new QChartView(&window); | |
|
44 | ||
|
45 | chartView->setChartTitle("Basic area chart example"); | |
|
46 | chartView->setRenderHint(QPainter::Antialiasing); | |
|
47 | ||
|
48 | chartView->addSeries(series); | |
|
49 | chartView->axisX()->setRange(0,20); | |
|
50 | chartView->axisY()->setRange(0,10); | |
|
51 | //![4] | |
|
52 | //![5] | |
|
53 | window.setCentralWidget(chartView); | |
|
54 | window.resize(400, 300); | |
|
55 | window.show(); | |
|
56 | //![5] | |
|
57 | ||
|
58 | return a.exec(); | |
|
59 | } |
@@ -0,0 +1,14 | |||
|
1 | INCLUDEPATH += $$PWD | |
|
2 | DEPENDPATH += $$PWD | |
|
3 | ||
|
4 | SOURCES += \ | |
|
5 | #$$PWD/areachartanimationitem.cpp \ | |
|
6 | $$PWD/areachartitem.cpp \ | |
|
7 | $$PWD/qareaseries.cpp | |
|
8 | ||
|
9 | PRIVATE_HEADERS += \ | |
|
10 | $$PWD/areachartitem_p.h \ | |
|
11 | # $$PWD/linechartanimationitem_p.h | |
|
12 | ||
|
13 | PUBLIC_HEADERS += \ | |
|
14 | $$PWD/qareaseries.h No newline at end of file |
@@ -0,0 +1,63 | |||
|
1 | #include "linechartanimationitem_p.h" | |
|
2 | #include "linechartitem_p.h" | |
|
3 | #include <QPropertyAnimation> | |
|
4 | ||
|
5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
6 | ||
|
7 | const static int duration = 500; | |
|
8 | ||
|
9 | ||
|
10 | LineChartAnimationItem::LineChartAnimationItem(ChartPresenter* presenter, QLineSeries* series,QGraphicsItem *parent): | |
|
11 | LineChartItem(presenter,series,parent) | |
|
12 | { | |
|
13 | ||
|
14 | } | |
|
15 | ||
|
16 | LineChartAnimationItem::~LineChartAnimationItem() | |
|
17 | { | |
|
18 | } | |
|
19 | ||
|
20 | void LineChartAnimationItem::addPoints(const QVector<QPointF>& points) | |
|
21 | { | |
|
22 | m_data=points; | |
|
23 | clearView(); | |
|
24 | QPropertyAnimation *animation = new QPropertyAnimation(this, "a_addPoints", parent()); | |
|
25 | animation->setDuration(duration); | |
|
26 | //animation->setEasingCurve(QEasingCurve::InOutBack); | |
|
27 | animation->setKeyValueAt(0.0, 0); | |
|
28 | animation->setKeyValueAt(1.0, m_data.size()); | |
|
29 | animation->start(QAbstractAnimation::DeleteWhenStopped); | |
|
30 | } | |
|
31 | ||
|
32 | void LineChartAnimationItem::setPoint(int index,const QPointF& point) | |
|
33 | { | |
|
34 | AnimationHelper* helper = new AnimationHelper(this,index); | |
|
35 | QPropertyAnimation *animation = new QPropertyAnimation(helper, "point", parent()); | |
|
36 | animation->setDuration(duration); | |
|
37 | //animation->setEasingCurve(QEasingCurve::InOutBack); | |
|
38 | animation->setKeyValueAt(0.0, points().value(index)); | |
|
39 | animation->setKeyValueAt(1.0, point); | |
|
40 | animation->start(QAbstractAnimation::DeleteWhenStopped); | |
|
41 | } | |
|
42 | ||
|
43 | void LineChartAnimationItem::aw_addPoints(int points) | |
|
44 | { | |
|
45 | int index = count(); | |
|
46 | for(int i = index;i< points ;i++){ | |
|
47 | LineChartItem::addPoint(m_data.at(i)); | |
|
48 | } | |
|
49 | updateGeometry(); | |
|
50 | update(); | |
|
51 | } | |
|
52 | ||
|
53 | void LineChartAnimationItem::aw_setPoint(int index,const QPointF& point) | |
|
54 | { | |
|
55 | LineChartItem::setPoint(index,point); | |
|
56 | updateGeometry(); | |
|
57 | update(); | |
|
58 | } | |
|
59 | ||
|
60 | ||
|
61 | #include "moc_linechartanimationitem_p.cpp" | |
|
62 | ||
|
63 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,55 | |||
|
1 | #ifndef LINECHARTANIMATIONITEM_P_H_ | |
|
2 | #define LINECHARTANIMATIONITEM_P_H_ | |
|
3 | ||
|
4 | #include "qchartglobal.h" | |
|
5 | #include "linechartitem_p.h" | |
|
6 | #include "domain_p.h" | |
|
7 | ||
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
9 | ||
|
10 | class LineChartItem; | |
|
11 | ||
|
12 | class LineChartAnimationItem : public LineChartItem { | |
|
13 | Q_OBJECT | |
|
14 | Q_PROPERTY(int a_addPoints READ ar_addPoints WRITE aw_addPoints); | |
|
15 | // Q_PROPERTY(QPointF a_setPoint READ ar_setPoint WRITE aw_setPoint); | |
|
16 | public: | |
|
17 | LineChartAnimationItem(ChartPresenter* presenter, QLineSeries *series, QGraphicsItem *parent = 0); | |
|
18 | virtual ~LineChartAnimationItem(); | |
|
19 | ||
|
20 | void addPoints(const QVector<QPointF>& points); | |
|
21 | void setPoint(int index,const QPointF& point); | |
|
22 | //void removePoint(const QPointF& point){}; | |
|
23 | //void setPoint(const QPointF& oldPoint, const QPointF& newPoint){}; | |
|
24 | ||
|
25 | int ar_addPoints() const { return m_addPoints;} | |
|
26 | void aw_addPoints(int points); | |
|
27 | const QPointF& ar_setPoint() const { return m_setPoint;} | |
|
28 | void aw_setPoint(int index,const QPointF& point); | |
|
29 | ||
|
30 | private: | |
|
31 | QVector<QPointF> m_data; | |
|
32 | Domain m_domain; | |
|
33 | int m_addPoints; | |
|
34 | QPointF m_setPoint; | |
|
35 | int m_setPoint_index; | |
|
36 | }; | |
|
37 | ||
|
38 | class AnimationHelper: public QObject | |
|
39 | { | |
|
40 | Q_OBJECT | |
|
41 | Q_PROPERTY(QPointF point READ point WRITE setPoint); | |
|
42 | public: | |
|
43 | AnimationHelper(LineChartAnimationItem* item,int index):m_item(item),m_index(index){}; | |
|
44 | void setPoint(const QPointF& point){ | |
|
45 | m_item->aw_setPoint(m_index,point); | |
|
46 | } | |
|
47 | QPointF point(){return m_point;} | |
|
48 | QPointF m_point; | |
|
49 | LineChartAnimationItem* m_item; | |
|
50 | int m_index; | |
|
51 | }; | |
|
52 | ||
|
53 | QTCOMMERCIALCHART_END_NAMESPACE | |
|
54 | ||
|
55 | #endif |
@@ -0,0 +1,116 | |||
|
1 | #include "areachartitem_p.h" | |
|
2 | #include "qareaseries.h" | |
|
3 | #include "qlineseries.h" | |
|
4 | #include "chartpresenter_p.h" | |
|
5 | #include <QPainter> | |
|
6 | ||
|
7 | ||
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
9 | ||
|
10 | //TODO: optimize : remove points which are not visible | |
|
11 | ||
|
12 | AreaChartItem::AreaChartItem(ChartPresenter* presenter, QAreaSeries* areaSeries,QGraphicsItem *parent):ChartItem(parent), | |
|
13 | m_presenter(presenter), | |
|
14 | m_series(areaSeries), | |
|
15 | m_upper(0), | |
|
16 | m_lower(0) | |
|
17 | { | |
|
18 | //m_items.setZValue(ChartPresenter::LineChartZValue); | |
|
19 | m_upper = new AreaBoundItem(this,presenter,m_series->upperSeries()); | |
|
20 | if(m_series->lowerSeries()){ | |
|
21 | m_lower = new AreaBoundItem(this,presenter,m_series->lowerSeries()); | |
|
22 | } | |
|
23 | setZValue(ChartPresenter::LineChartZValue); | |
|
24 | ||
|
25 | QObject::connect(presenter,SIGNAL(geometryChanged(const QRectF&)),this,SLOT(handleGeometryChanged(const QRectF&))); | |
|
26 | QObject::connect(areaSeries,SIGNAL(updated()),this,SLOT(handleUpdated())); | |
|
27 | ||
|
28 | handleUpdated(); | |
|
29 | } | |
|
30 | ||
|
31 | AreaChartItem::~AreaChartItem() | |
|
32 | { | |
|
33 | delete m_upper; | |
|
34 | delete m_lower; | |
|
35 | }; | |
|
36 | ||
|
37 | QRectF AreaChartItem::boundingRect() const | |
|
38 | { | |
|
39 | return m_rect; | |
|
40 | } | |
|
41 | ||
|
42 | QPainterPath AreaChartItem::shape() const | |
|
43 | { | |
|
44 | return m_path; | |
|
45 | } | |
|
46 | ||
|
47 | void AreaChartItem::setPen(const QPen& pen) | |
|
48 | { | |
|
49 | m_pen = pen; | |
|
50 | } | |
|
51 | ||
|
52 | void AreaChartItem::setBrush(const QBrush& brush) | |
|
53 | { | |
|
54 | m_brush = brush; | |
|
55 | } | |
|
56 | ||
|
57 | void AreaChartItem::updatePath() | |
|
58 | { | |
|
59 | QPainterPath path; | |
|
60 | ||
|
61 | path.connectPath(m_upper->shape()); | |
|
62 | if(m_lower){ | |
|
63 | path.connectPath(m_lower->shape().toReversed()); | |
|
64 | } | |
|
65 | else{ | |
|
66 | QPointF first = path.pointAtPercent(0); | |
|
67 | QPointF last = path.pointAtPercent(1); | |
|
68 | path.lineTo(last.x(),m_clipRect.bottom()); | |
|
69 | path.lineTo(first.x(),m_clipRect.bottom()); | |
|
70 | } | |
|
71 | path.closeSubpath(); | |
|
72 | prepareGeometryChange(); | |
|
73 | m_path=path; | |
|
74 | m_rect=path.boundingRect(); | |
|
75 | update(); | |
|
76 | } | |
|
77 | ||
|
78 | void AreaChartItem::handleUpdated() | |
|
79 | { | |
|
80 | setPen(m_series->pen()); | |
|
81 | setBrush(m_series->brush()); | |
|
82 | update(); | |
|
83 | } | |
|
84 | ||
|
85 | void AreaChartItem::handleDomainChanged(const Domain& domain) | |
|
86 | { | |
|
87 | m_upper->handleDomainChanged(domain); | |
|
88 | if(m_lower) | |
|
89 | m_lower->handleDomainChanged(domain); | |
|
90 | } | |
|
91 | ||
|
92 | void AreaChartItem::handleGeometryChanged(const QRectF& rect) | |
|
93 | { | |
|
94 | m_clipRect=rect.translated(-rect.topLeft()); | |
|
95 | setPos(rect.topLeft()); | |
|
96 | m_upper->handleGeometryChanged(rect); | |
|
97 | if(m_lower) | |
|
98 | m_lower->handleGeometryChanged(rect); | |
|
99 | } | |
|
100 | //painter | |
|
101 | ||
|
102 | void AreaChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
|
103 | { | |
|
104 | Q_UNUSED(widget); | |
|
105 | Q_UNUSED(option); | |
|
106 | painter->save(); | |
|
107 | painter->setPen(m_pen); | |
|
108 | painter->setBrush(m_brush); | |
|
109 | painter->setClipRect(m_clipRect); | |
|
110 | painter->drawPath(m_path); | |
|
111 | painter->restore(); | |
|
112 | } | |
|
113 | ||
|
114 | #include "moc_areachartitem_p.cpp" | |
|
115 | ||
|
116 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,67 | |||
|
1 | #ifndef AREACHARTITEM_H | |
|
2 | #define AREACHARTITEM_H | |
|
3 | ||
|
4 | #include "qchartglobal.h" | |
|
5 | #include "linechartitem_p.h" | |
|
6 | #include <QPen> | |
|
7 | ||
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
9 | ||
|
10 | class ChartPresenter; | |
|
11 | class QAreaSeries; | |
|
12 | class AreaChartItem; | |
|
13 | ||
|
14 | class AreaChartItem : public QObject ,public ChartItem | |
|
15 | { | |
|
16 | Q_OBJECT | |
|
17 | public: | |
|
18 | AreaChartItem(ChartPresenter* presenter, QAreaSeries* areaSeries, QGraphicsItem *parent = 0); | |
|
19 | ~ AreaChartItem(); | |
|
20 | ||
|
21 | //from QGraphicsItem | |
|
22 | QRectF boundingRect() const; | |
|
23 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
|
24 | QPainterPath shape() const; | |
|
25 | ||
|
26 | void setPen(const QPen& pen); | |
|
27 | void setBrush(const QBrush& brush); | |
|
28 | void setPointsVisible(bool visible); | |
|
29 | void updatePath(); | |
|
30 | public slots: | |
|
31 | void handleUpdated(); | |
|
32 | void handleDomainChanged(const Domain& domain); | |
|
33 | void handleGeometryChanged(const QRectF& size); | |
|
34 | ||
|
35 | private: | |
|
36 | ChartPresenter* m_presenter; | |
|
37 | QPainterPath m_path; | |
|
38 | QAreaSeries* m_series; | |
|
39 | LineChartItem* m_upper; | |
|
40 | LineChartItem* m_lower; | |
|
41 | QRectF m_rect; | |
|
42 | QRectF m_clipRect; | |
|
43 | QPen m_pen; | |
|
44 | QBrush m_brush; | |
|
45 | }; | |
|
46 | ||
|
47 | class AreaBoundItem : public LineChartItem | |
|
48 | { | |
|
49 | public: | |
|
50 | AreaBoundItem(AreaChartItem* item,ChartPresenter* presenter, QLineSeries* lineSeries):LineChartItem(presenter,lineSeries), | |
|
51 | m_item(item){}; | |
|
52 | ||
|
53 | ~AreaBoundItem(){}; | |
|
54 | ||
|
55 | void applyGeometry(QVector<QPointF>& points){ | |
|
56 | LineChartItem::applyGeometry(points); | |
|
57 | m_item->updatePath(); | |
|
58 | } | |
|
59 | ||
|
60 | private: | |
|
61 | AreaChartItem* m_item; | |
|
62 | ||
|
63 | }; | |
|
64 | ||
|
65 | QTCOMMERCIALCHART_END_NAMESPACE | |
|
66 | ||
|
67 | #endif |
@@ -0,0 +1,115 | |||
|
1 | #include "qareaseries.h" | |
|
2 | #include "qlineseries.h" | |
|
3 | ||
|
4 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
5 | ||
|
6 | /*! | |
|
7 | \class QAreaSeries | |
|
8 | \brief The QAreaSeries class is used for making area charts. | |
|
9 | ||
|
10 | \mainclass | |
|
11 | ||
|
12 | An area chart is used to show quantitative data. It is based on line chart, in the way that area between axis and the line | |
|
13 | is emphasized with color. Since the area chart is based on line chart, QAreaSeries constructor needs QLineSeries instance, | |
|
14 | which defines "upper" boundary of the area. "Lower" boundary is defined by default by axis X (y=0). Instead of axis X "lower" boundary can be also specified also by other line. | |
|
15 | In that case QAreaSeries should be initiated with two QLineSerie instances. Please note terms "upper" and "lower" boundary can be misleading in cases | |
|
16 | where "lower" boundary had bigger values than the "upper" one, however the main point that area between these two boundary will be filled. | |
|
17 | ||
|
18 | \image areachart.png | |
|
19 | ||
|
20 | Creating basic area chart is simple: | |
|
21 | \code | |
|
22 | QLineSeries* lineSeries = new QLineSeries(); | |
|
23 | series->add(0, 6); | |
|
24 | series->add(2, 4); | |
|
25 | QAreaSeries* areaSeries = new QAreaSeries(lineSeries); | |
|
26 | ... | |
|
27 | chartView->addSeries(areaSeries); | |
|
28 | \endcode | |
|
29 | */ | |
|
30 | ||
|
31 | /*! | |
|
32 | \fn virtual QSeriesType QAreaSeries::type() const | |
|
33 | \brief Returns type of series. | |
|
34 | \sa QSeries, QSeriesType | |
|
35 | */ | |
|
36 | ||
|
37 | /*! | |
|
38 | \fn QLineSeries* QAreaSeries::upperSeries() const | |
|
39 | \brief Returns upperSeries used to define one of area boundaries. | |
|
40 | */ | |
|
41 | ||
|
42 | /*! | |
|
43 | \fn QLineSeries* QAreaSeries::lowerSeries() const | |
|
44 | \brief Returns lowerSeries used to define one of area boundaries. Note if QAreaSeries where counstucted wihtout a\ lowerSeries | |
|
45 | this function return Null pointer. | |
|
46 | */ | |
|
47 | ||
|
48 | /*! | |
|
49 | \fn QPen QAreaSeries::pen() const | |
|
50 | \brief Returns the pen used to draw line for this series. | |
|
51 | \sa setPen() | |
|
52 | */ | |
|
53 | ||
|
54 | /*! | |
|
55 | \fn QPen QAreaSeries::brush() const | |
|
56 | \brief Returns the brush used to draw line for this series. | |
|
57 | \sa setBrush() | |
|
58 | */ | |
|
59 | ||
|
60 | /*! | |
|
61 | \fn bool QAreaSeries::pointsVisible() const | |
|
62 | \brief Returns if the points are drawn for this series. | |
|
63 | \sa setPointsVisible() | |
|
64 | */ | |
|
65 | ||
|
66 | /*! | |
|
67 | \fn void QAreaSeries::updated() | |
|
68 | \brief \internal | |
|
69 | */ | |
|
70 | ||
|
71 | /*! | |
|
72 | Constructs area series object which is a child of \a upperSeries. Area will be spanned between \a | |
|
73 | upperSeries line and \a lowerSeries line. If no \a lowerSeries is passed to constructor, area is specified by axis x (y=0) instead. | |
|
74 | When series object is added to QChartView or QChart instance ownerships is transfered. | |
|
75 | */ | |
|
76 | QAreaSeries::QAreaSeries(QLineSeries* upperSeries,QLineSeries* lowerSeries):QSeries(upperSeries), | |
|
77 | m_upperSeries(upperSeries), | |
|
78 | m_lowerSeries(lowerSeries), | |
|
79 | m_pointsVisible(false) | |
|
80 | { | |
|
81 | } | |
|
82 | /*! | |
|
83 | Destroys the object. Series added to QChartView or QChart instances are owned by those, | |
|
84 | and are deleted when mentioned object are destroyed. | |
|
85 | */ | |
|
86 | QAreaSeries::~QAreaSeries() | |
|
87 | { | |
|
88 | } | |
|
89 | ||
|
90 | /*! | |
|
91 | Sets \a pen used for drawing area outline. | |
|
92 | */ | |
|
93 | void QAreaSeries::setPen(const QPen& pen) | |
|
94 | { | |
|
95 | m_pen=pen; | |
|
96 | } | |
|
97 | ||
|
98 | /*! | |
|
99 | Sets \a brush used for filling the area. | |
|
100 | */ | |
|
101 | void QAreaSeries::setBrush(const QBrush& brush) | |
|
102 | { | |
|
103 | m_brush=brush; | |
|
104 | } | |
|
105 | /*! | |
|
106 | Sets if data points are \a visible and should be drawn on line. | |
|
107 | */ | |
|
108 | void QAreaSeries::setPointsVisible(bool visible) | |
|
109 | { | |
|
110 | m_pointsVisible=visible; | |
|
111 | } | |
|
112 | ||
|
113 | #include "moc_qareaseries.cpp" | |
|
114 | ||
|
115 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,48 | |||
|
1 | #ifndef QAREASERIES_H_ | |
|
2 | #define QAREASERIES_H_ | |
|
3 | ||
|
4 | #include "qchartglobal.h" | |
|
5 | #include "qseries.h" | |
|
6 | #include <QDebug> | |
|
7 | #include <QPen> | |
|
8 | #include <QBrush> | |
|
9 | ||
|
10 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
11 | class QLineSeries; | |
|
12 | ||
|
13 | class QTCOMMERCIALCHART_EXPORT QAreaSeries : public QSeries | |
|
14 | { | |
|
15 | Q_OBJECT | |
|
16 | public: | |
|
17 | QAreaSeries(QLineSeries* upperSeries,QLineSeries* lowerSeries=0); | |
|
18 | virtual ~QAreaSeries(); | |
|
19 | ||
|
20 | public: // from QChartSeries | |
|
21 | virtual QSeriesType type() const { return QSeries::SeriesTypeArea;} | |
|
22 | ||
|
23 | QLineSeries* upperSeries() const { return m_upperSeries;} | |
|
24 | QLineSeries* lowerSeries() const { return m_lowerSeries;} | |
|
25 | ||
|
26 | void setPen(const QPen& pen); | |
|
27 | QPen pen() const { return m_pen;} | |
|
28 | ||
|
29 | void setBrush(const QBrush& brush); | |
|
30 | QBrush brush() const { return m_brush;} | |
|
31 | ||
|
32 | void setPointsVisible(bool visible); | |
|
33 | bool pointsVisible() const {return m_pointsVisible;} | |
|
34 | ||
|
35 | signals: | |
|
36 | void updated(); | |
|
37 | ||
|
38 | private: | |
|
39 | QBrush m_brush; | |
|
40 | QPen m_pen; | |
|
41 | QLineSeries* m_upperSeries; | |
|
42 | QLineSeries* m_lowerSeries; | |
|
43 | bool m_pointsVisible; | |
|
44 | }; | |
|
45 | ||
|
46 | QTCOMMERCIALCHART_END_NAMESPACE | |
|
47 | ||
|
48 | #endif |
@@ -13,6 +13,7 | |||
|
13 | 13 | <tr> |
|
14 | 14 | <td valign="top"> |
|
15 | 15 | <ul> |
|
16 | <li><a href="qareaseries.html">QAreaSeries</a></li> | |
|
16 | 17 | <li><a href="qbarseries.html">QBarSeries</a></li> |
|
17 | 18 | <li><a href="qbarset.html">QBarSet</a></li> |
|
18 | 19 | <li><a href="qchart.html">QChart</a></li> |
@@ -13,6 +13,7 | |||
|
13 | 13 | <tr> |
|
14 | 14 | <td valign="top"> |
|
15 | 15 | <ul> |
|
16 | <li><a href="example-areachart.html">Area Chart example</a></li> | |
|
16 | 17 | <li><a href="example-barchart.html">Bar Chart example</a></li> |
|
17 | 18 | <li><a href="example-stackedbarchart.html">Stacked Bar Chart example</a></li> |
|
18 | 19 | <li><a href="example-percentbarchart.html">Percent Bar Chart example</a></li> |
@@ -16,21 +16,22 | |||
|
16 | 16 | |
|
17 | 17 | <table><tr> |
|
18 | 18 | <td><a href="example-linechart.html"><img src="images/linechart.png" alt="linechart" /></a></td> |
|
19 |
<td><a href="example- |
|
|
19 | <td><a href="example-areachart.html"><img src="images/areachart.png" alt="areachart" /></a></td> | |
|
20 | 20 | </tr> |
|
21 | 21 | <tr> |
|
22 | <td><a href="example-barchart.html"><img src="images/barchart.png" alt="barchart" /></a></td> | |
|
22 | 23 | <td><a href="example-percentbarchart.html"><img src="images/percentbarchart.png" alt="percentbarcchart" /></a></td> |
|
23 | <td><a href="example-stackedbarchart.html"><img src="images/stackedbarchart.png" alt="stackedbarchart" /></a></td> | |
|
24 | 24 | </tr> |
|
25 | 25 | <tr> |
|
26 | <td><a href="example-stackedbarchart.html"><img src="images/stackedbarchart.png" alt="stackedbarchart" /></a></td> | |
|
26 | 27 | <td><img src="images/chartview_example.jpg " alt="linechart" /></td> |
|
27 | <td><img src="images/chartview_example_pie.jpg " alt="piechart" /></td> | |
|
28 | 28 | </tr><tr> |
|
29 | 29 | <td><img src="images/chartview_example_scatter.jpg " alt="scatterchart" /></td> |
|
30 | 30 | <td><img src="images/chartview_example_theme.jpg " alt="themechart" /></td> |
|
31 | 31 | </tr> |
|
32 | 32 | <tr> |
|
33 |
|
|
|
33 | <td><img src="images/chartview_example_bar.jpg " alt="barchart" /></td> | |
|
34 | <td><img src="images/chartview_example_pie.jpg " alt="piechart" /></td> | |
|
34 | 35 | </tr> |
|
35 | 36 | </table> |
|
36 | 37 | </div> |
@@ -14,4 +14,5 SUBDIRS += linechart \ | |||
|
14 | 14 | gdpbarchart \ |
|
15 | 15 | presenterchart \ |
|
16 | 16 | chartview \ |
|
17 | scatterinteractions | |
|
17 | scatterinteractions \ | |
|
18 | areachart |
@@ -2,6 +2,7 | |||
|
2 | 2 | #include "qchartaxis.h" |
|
3 | 3 | //series |
|
4 | 4 | #include "qlineseries.h" |
|
5 | #include "qareaseries.h" | |
|
5 | 6 | #include "qbarseries.h" |
|
6 | 7 | #include "qstackedbarseries.h" |
|
7 | 8 | #include "qpercentbarseries.h" |
@@ -57,12 +58,12 void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY) | |||
|
57 | 58 | { |
|
58 | 59 | case QSeries::SeriesTypeLine: { |
|
59 | 60 | |
|
60 |
QLineSeries* |
|
|
61 | QLineSeries* lineSeries = static_cast<QLineSeries*>(series); | |
|
61 | 62 | |
|
62 |
for (int i = 0; i < |
|
|
63 | for (int i = 0; i < lineSeries->count(); i++) | |
|
63 | 64 | { |
|
64 |
qreal x = |
|
|
65 |
qreal y = |
|
|
65 | qreal x = lineSeries->x(i); | |
|
66 | qreal y = lineSeries->y(i); | |
|
66 | 67 | domain.m_minX = qMin(domain.m_minX,x); |
|
67 | 68 | domain.m_minY = qMin(domain.m_minY,y); |
|
68 | 69 | domain.m_maxX = qMax(domain.m_maxX,x); |
@@ -70,6 +71,34 void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY) | |||
|
70 | 71 | } |
|
71 | 72 | break; |
|
72 | 73 | } |
|
74 | case QSeries::SeriesTypeArea: { | |
|
75 | ||
|
76 | QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series); | |
|
77 | ||
|
78 | QLineSeries* upperSeries = areaSeries->upperSeries(); | |
|
79 | QLineSeries* lowerSeries = areaSeries->lowerSeries(); | |
|
80 | ||
|
81 | for (int i = 0; i < upperSeries->count(); i++) | |
|
82 | { | |
|
83 | qreal x = upperSeries->x(i); | |
|
84 | qreal y = upperSeries->y(i); | |
|
85 | domain.m_minX = qMin(domain.m_minX,x); | |
|
86 | domain.m_minY = qMin(domain.m_minY,y); | |
|
87 | domain.m_maxX = qMax(domain.m_maxX,x); | |
|
88 | domain.m_maxY = qMax(domain.m_maxY,y); | |
|
89 | } | |
|
90 | if(lowerSeries){ | |
|
91 | for (int i = 0; i < lowerSeries->count(); i++) | |
|
92 | { | |
|
93 | qreal x = lowerSeries->x(i); | |
|
94 | qreal y = lowerSeries->y(i); | |
|
95 | domain.m_minX = qMin(domain.m_minX,x); | |
|
96 | domain.m_minY = qMin(domain.m_minY,y); | |
|
97 | domain.m_maxX = qMax(domain.m_maxX,x); | |
|
98 | domain.m_maxY = qMax(domain.m_maxY,y); | |
|
99 | }} | |
|
100 | break; | |
|
101 | } | |
|
73 | 102 | case QSeries::SeriesTypeBar: { |
|
74 | 103 | qDebug() << "QChartSeries::SeriesTypeBar"; |
|
75 | 104 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); |
@@ -8,11 +8,13 | |||
|
8 | 8 | #include "qstackedbarseries.h" |
|
9 | 9 | #include "qpercentbarseries.h" |
|
10 | 10 | #include "qlineseries.h" |
|
11 | #include "qareaseries.h" | |
|
11 | 12 | #include "qpieseries.h" |
|
12 | 13 | #include "qscatterseries.h" |
|
13 | 14 | //items |
|
14 | 15 | #include "axisitem_p.h" |
|
15 | 16 | #include "axisanimationitem_p.h" |
|
17 | #include "areachartitem_p.h" | |
|
16 | 18 | #include "barpresenter_p.h" |
|
17 | 19 | #include "stackedbarpresenter_p.h" |
|
18 | 20 | #include "percentbarpresenter_p.h" |
@@ -109,6 +111,7 void ChartPresenter::handleSeriesAdded(QSeries* series) | |||
|
109 | 111 | switch(series->type()) |
|
110 | 112 | { |
|
111 | 113 | case QSeries::SeriesTypeLine: { |
|
114 | ||
|
112 | 115 | QLineSeries* lineSeries = static_cast<QLineSeries*>(series); |
|
113 | 116 | LineChartItem* item; |
|
114 | 117 | if(m_options.testFlag(QChart::SeriesAnimations)){ |
@@ -117,14 +120,24 void ChartPresenter::handleSeriesAdded(QSeries* series) | |||
|
117 | 120 | item = new LineChartItem(this,lineSeries,m_chart); |
|
118 | 121 | } |
|
119 | 122 | m_chartTheme->decorate(item,lineSeries,m_chartItems.count()); |
|
120 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
|
121 | QObject::connect(lineSeries,SIGNAL(pointReplaced(int)),item,SLOT(handlePointReplaced(int))); | |
|
122 | QObject::connect(lineSeries,SIGNAL(pointAdded(int)),item,SLOT(handlePointAdded(int))); | |
|
123 | QObject::connect(lineSeries,SIGNAL(pointRemoved(int)),item,SLOT(handlePointRemoved(int))); | |
|
124 | QObject::connect(lineSeries,SIGNAL(updated()),item,SLOT(handleUpdated())); | |
|
125 | 123 | m_chartItems.insert(series,item); |
|
126 | 124 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); |
|
127 | item->handleUpdated(); | |
|
125 | break; | |
|
126 | } | |
|
127 | ||
|
128 | case QSeries::SeriesTypeArea: { | |
|
129 | ||
|
130 | QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series); | |
|
131 | AreaChartItem* item; | |
|
132 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
|
133 | item = new AreaChartItem(this,areaSeries,m_chart); | |
|
134 | } | |
|
135 | else { | |
|
136 | item = new AreaChartItem(this,areaSeries,m_chart); | |
|
137 | } | |
|
138 | m_chartTheme->decorate(item,areaSeries,m_chartItems.count()); | |
|
139 | m_chartItems.insert(series,item); | |
|
140 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); | |
|
128 | 141 | break; |
|
129 | 142 | } |
|
130 | 143 |
@@ -9,6 +9,7 | |||
|
9 | 9 | #include "qstackedbarseries.h" |
|
10 | 10 | #include "qpercentbarseries.h" |
|
11 | 11 | #include "qlineseries.h" |
|
12 | #include "qareaseries.h" | |
|
12 | 13 | #include "qscatterseries.h" |
|
13 | 14 | #include "qpieseries.h" |
|
14 | 15 | #include "qpieslice.h" |
@@ -19,6 +20,7 | |||
|
19 | 20 | #include "stackedbarpresenter_p.h" |
|
20 | 21 | #include "percentbarpresenter_p.h" |
|
21 | 22 | #include "linechartitem_p.h" |
|
23 | #include "areachartitem_p.h" | |
|
22 | 24 | #include "scatterpresenter_p.h" |
|
23 | 25 | #include "piepresenter_p.h" |
|
24 | 26 | |
@@ -59,7 +61,7 ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) | |||
|
59 | 61 | { |
|
60 | 62 | switch(theme) { |
|
61 | 63 | case QChart::ChartThemeDefault: |
|
62 |
return new ChartTheme |
|
|
64 | return new ChartTheme(); | |
|
63 | 65 | case QChart::ChartThemeVanilla: |
|
64 | 66 | return new ChartThemeVanilla(); |
|
65 | 67 | case QChart::ChartThemeIcy: |
@@ -90,6 +92,12 void ChartTheme::decorate(ChartItem* item, QSeries* series,int count) | |||
|
90 | 92 | decorate(i,s,count); |
|
91 | 93 | break; |
|
92 | 94 | } |
|
95 | case QSeries::SeriesTypeArea: { | |
|
96 | QAreaSeries* s = static_cast<QAreaSeries*>(series); | |
|
97 | AreaChartItem* i = static_cast<AreaChartItem*>(item); | |
|
98 | decorate(i,s,count); | |
|
99 | break; | |
|
100 | } | |
|
93 | 101 | case QSeries::SeriesTypeBar: { |
|
94 | 102 | QBarSeries* b = static_cast<QBarSeries*>(series); |
|
95 | 103 | BarPresenter* i = static_cast<BarPresenter*>(item); |
@@ -129,6 +137,28 void ChartTheme::decorate(ChartItem* item, QSeries* series,int count) | |||
|
129 | 137 | |
|
130 | 138 | } |
|
131 | 139 | |
|
140 | void ChartTheme::decorate(AreaChartItem* item, QAreaSeries* series,int count) | |
|
141 | { | |
|
142 | QPen pen; | |
|
143 | QBrush brush; | |
|
144 | ||
|
145 | if(pen != series->pen()){ | |
|
146 | item->setPen(series->pen()); | |
|
147 | }else{ | |
|
148 | pen.setColor(m_seriesColor.at(count%m_seriesColor.size())); | |
|
149 | pen.setWidthF(2); | |
|
150 | item->setPen(pen); | |
|
151 | } | |
|
152 | ||
|
153 | if(brush != series->brush()){ | |
|
154 | item->setBrush(series->brush()); | |
|
155 | }else{ | |
|
156 | QBrush brush(m_seriesColor.at(count%m_seriesColor.size())); | |
|
157 | item->setBrush(brush); | |
|
158 | } | |
|
159 | } | |
|
160 | ||
|
161 | ||
|
132 | 162 | void ChartTheme::decorate(LineChartItem* item, QLineSeries* series,int count) |
|
133 | 163 | { |
|
134 | 164 | QPen pen; |
@@ -21,6 +21,8 class QScatterSeries; | |||
|
21 | 21 | class ScatterPresenter; |
|
22 | 22 | class PiePresenter; |
|
23 | 23 | class QPieSeries; |
|
24 | class AreaChartItem; | |
|
25 | class QAreaSeries; | |
|
24 | 26 | |
|
25 | 27 | class ChartTheme |
|
26 | 28 | { |
@@ -34,7 +36,8 public: | |||
|
34 | 36 | void decorate(BarPresenter* item, QBarSeries* series,int count); |
|
35 | 37 | void decorate(StackedBarPresenter* item, QStackedBarSeries* series,int count); |
|
36 | 38 | void decorate(PercentBarPresenter* item, QPercentBarSeries* series,int count); |
|
37 |
void decorate(LineChartItem* item, QLineSeries*, |
|
|
39 | void decorate(LineChartItem* item, QLineSeries* series,int count); | |
|
40 | void decorate(AreaChartItem* item, QAreaSeries* series,int count); | |
|
38 | 41 | void decorate(ScatterPresenter* presenter, QScatterSeries* series, int count); |
|
39 | 42 | void decorate(PiePresenter* item, QPieSeries* series, int count); |
|
40 | 43 | void decorate(QChartAxis* axis,AxisItem* item); |
@@ -15,6 +15,12 m_items(this) | |||
|
15 | 15 | { |
|
16 | 16 | //m_items.setZValue(ChartPresenter::LineChartZValue); |
|
17 | 17 | setZValue(ChartPresenter::LineChartZValue); |
|
18 | ||
|
19 | QObject::connect(presenter,SIGNAL(geometryChanged(const QRectF&)),this,SLOT(handleGeometryChanged(const QRectF&))); | |
|
20 | QObject::connect(series,SIGNAL(pointReplaced(int)),this,SLOT(handlePointReplaced(int))); | |
|
21 | QObject::connect(series,SIGNAL(pointAdded(int)),this,SLOT(handlePointAdded(int))); | |
|
22 | QObject::connect(series,SIGNAL(pointRemoved(int)),this,SLOT(handlePointRemoved(int))); | |
|
23 | QObject::connect(series,SIGNAL(updated()),this,SLOT(handleUpdated())); | |
|
18 | 24 | } |
|
19 | 25 | |
|
20 | 26 | QRectF LineChartItem::boundingRect() const |
@@ -36,7 +36,7 public slots: | |||
|
36 | 36 | public: |
|
37 | 37 | virtual void updateItem(QVector<QPointF>& oldPoints,QVector<QPointF>& newPoints); |
|
38 | 38 | virtual void updateItem(QVector<QPointF>& oldPoints,int index,QPointF& newPoint); |
|
39 | void applyGeometry(QVector<QPointF>& points); | |
|
39 | virtual void applyGeometry(QVector<QPointF>& points); | |
|
40 | 40 | void createPoints(int count); |
|
41 | 41 | void clearPoints(int count); |
|
42 | 42 | QPointF calculateGeometryPoint(int index) const; |
General Comments 0
You need to be logged in to leave comments.
Login now