1 | NO CONTENT: new file 100644, binary diff hidden |
|
NO CONTENT: new file 100644, binary diff hidden |
1 | NO CONTENT: new file 100644, binary diff hidden |
|
NO CONTENT: new file 100644, binary diff hidden |
@@ -0,0 +1,21 | |||||
|
1 | /*! | |||
|
2 | \example examples/customcolors | |||
|
3 | \title CustomColors Example | |||
|
4 | \subtitle | |||
|
5 | ||||
|
6 | The example shows how to customize different visual elements on a typical chart i.e. customize | |||
|
7 | the following chart: | |||
|
8 | \image custom_colors1.jpg | |||
|
9 | ||||
|
10 | to look like this instead: | |||
|
11 | \image custom_colors2.jpg | |||
|
12 | ||||
|
13 | Customize chart background with the company specific colors: | |||
|
14 | \snippet ../examples/customcolors/mainwindow.cpp 1 | |||
|
15 | ||||
|
16 | Customize chart axes: | |||
|
17 | \snippet ../examples/customcolors/mainwindow.cpp 2 | |||
|
18 | ||||
|
19 | Customize pen and brush of all the series we have: | |||
|
20 | \snippet ../examples/customcolors/mainwindow.cpp 3 | |||
|
21 | */ No newline at end of file |
@@ -1,31 +1,32 | |||||
1 | /*! |
|
1 | /*! | |
2 | \page examples.html |
|
2 | \page examples.html | |
3 | \title Examples |
|
3 | \title Examples | |
4 | \keyword Examples |
|
4 | \keyword Examples | |
5 |
|
5 | |||
6 | \raw HTML |
|
6 | \raw HTML | |
7 | <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable"> |
|
7 | <table cellpadding="2" cellspacing="1" border="0" width="100%" class="indextable"> | |
8 | <tr> |
|
8 | <tr> | |
9 | <th class="titleheader" width="33%"> |
|
9 | <th class="titleheader" width="33%"> | |
10 | List of examples |
|
10 | List of examples | |
11 | </th> |
|
11 | </th> | |
12 | </tr> |
|
12 | </tr> | |
13 | <tr> |
|
13 | <tr> | |
14 | <td valign="top"> |
|
14 | <td valign="top"> | |
15 | <ul> |
|
15 | <ul> | |
16 | <li><a href="example-areachart.html">Area Chart example</a></li> |
|
16 | <li><a href="example-areachart.html">Area Chart example</a></li> | |
17 | <li><a href="example-barchart.html">Bar Chart example</a></li> |
|
17 | <li><a href="example-barchart.html">Bar Chart example</a></li> | |
18 | <li><a href="example-linechart.html">Line Chart example</a></li> |
|
18 | <li><a href="example-linechart.html">Line Chart example</a></li> | |
19 | <li><a href="example-percentbarchart.html">Percent Bar Chart example</a></li> |
|
19 | <li><a href="example-percentbarchart.html">Percent Bar Chart example</a></li> | |
20 | <li><a href="example-piechart.html">Pie Chart example</a></li> |
|
20 | <li><a href="example-piechart.html">Pie Chart example</a></li> | |
21 | <li><a href="example-presenterchart.html">Presenter Chart example</a></li> |
|
21 | <li><a href="example-presenterchart.html">Presenter Chart example</a></li> | |
22 | <li><a href="example-scatterchart.html">Scatter Chart example</a></li> |
|
22 | <li><a href="example-scatterchart.html">Scatter Chart example</a></li> | |
23 | <li><a href="example-splinechart.html">Spline Chart example</a></li> |
|
23 | <li><a href="example-splinechart.html">Spline Chart example</a></li> | |
24 | <li><a href="example-stackedbarchart.html">Stacked Bar Chart example</a></li> |
|
24 | <li><a href="example-stackedbarchart.html">Stacked Bar Chart example</a></li> | |
25 | <li><a href="example-stackedbarchartdrilldown.html">Stacked Bar Chart Drilldown example</a></li> |
|
25 | <li><a href="example-stackedbarchartdrilldown.html">Stacked Bar Chart Drilldown example</a></li> | |
|
26 | <li><a href="examples-customcolors.html">Customizing colors example</a></li> | |||
26 | </ul> |
|
27 | </ul> | |
27 | </td> |
|
28 | </td> | |
28 | </tr> |
|
29 | </tr> | |
29 | </table> |
|
30 | </table> | |
30 | \endraw |
|
31 | \endraw | |
31 | */ |
|
32 | */ |
@@ -1,97 +1,104 | |||||
1 | #include "mainwindow.h" |
|
1 | #include "mainwindow.h" | |
2 | #include <qchartview.h> |
|
2 | #include <qchartview.h> | |
3 | #include <qpieseries.h> |
|
3 | #include <qpieseries.h> | |
4 | #include <qpieslice.h> |
|
4 | #include <qpieslice.h> | |
5 | #include <qlineseries.h> |
|
5 | #include <qlineseries.h> | |
6 | #include <qscatterseries.h> |
|
6 | #include <qscatterseries.h> | |
7 | #include <qchartaxis.h> |
|
7 | #include <qchartaxis.h> | |
8 | #include <QDebug> |
|
8 | #include <QDebug> | |
9 |
|
9 | |||
10 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
10 | QTCOMMERCIALCHART_USE_NAMESPACE | |
11 |
|
11 | |||
12 | MainWindow::MainWindow(QWidget *parent) |
|
12 | MainWindow::MainWindow(QWidget *parent) | |
13 | : QMainWindow(parent) |
|
13 | : QMainWindow(parent) | |
14 | { |
|
14 | { | |
15 | // Here's the set of company's colors used throughout the example |
|
15 | // Here's the set of company's colors used throughout the example | |
16 | m_companyColor1 = "#b90020"; |
|
16 | m_companyColor1 = "#b90020"; | |
17 | m_companyColor2 = "#6d0013"; |
|
17 | m_companyColor2 = "#6d0013"; | |
18 |
m_companyColor3 = "#d5d5 |
|
18 | m_companyColor3 = "#f5d5d5"; | |
19 | m_companyColor4 = "#fcfcfc"; |
|
19 | m_companyColor4 = "#fcfcfc"; | |
20 |
|
20 | |||
21 | resize(400, 300); |
|
21 | resize(400, 300); | |
22 | setWindowFlags(Qt::FramelessWindowHint); |
|
22 | setWindowFlags(Qt::FramelessWindowHint); | |
23 |
|
23 | |||
24 | // Create chart view |
|
24 | // Create chart view | |
25 | m_chartView = new QChartView(this); |
|
25 | m_chartView = new QChartView(this); | |
26 | setCentralWidget(m_chartView); |
|
26 | setCentralWidget(m_chartView); | |
27 | m_chartView->setChartTitle("Custom colors example"); |
|
27 | m_chartView->setChartTitle("Custom colors example"); | |
28 | m_chartView->setRenderHint(QPainter::Antialiasing); |
|
28 | m_chartView->setRenderHint(QPainter::Antialiasing); | |
29 |
|
29 | |||
30 | // Create line series |
|
30 | // Create line series | |
31 | m_line = new QLineSeries(); |
|
31 | m_line = new QLineSeries(); | |
32 | m_line->add(0.0, 1.1); |
|
32 | m_line->add(0.0, 1.1); | |
33 | m_line->add(1.0, 2.3); |
|
33 | m_line->add(1.0, 2.3); | |
34 | m_line->add(2.0, 2.1); |
|
34 | m_line->add(2.0, 2.1); | |
35 | m_line->add(3.0, 3.3); |
|
35 | m_line->add(3.0, 3.3); | |
36 | m_chartView->addSeries(m_line); |
|
36 | m_chartView->addSeries(m_line); | |
37 |
|
37 | |||
38 | // Create scatter series with the same data |
|
38 | // Create scatter series with the same data | |
39 | m_scatter = new QScatterSeries(); |
|
39 | m_scatter = new QScatterSeries(); | |
40 | m_scatter->add(m_line->data()); |
|
40 | m_scatter->add(m_line->data()); | |
41 | m_chartView->addSeries(m_scatter); |
|
41 | m_chartView->addSeries(m_scatter); | |
42 |
|
42 | |||
43 | // Create pie series with different data |
|
43 | // Create pie series with different data | |
44 | m_pie = new QPieSeries(); |
|
44 | m_pie = new QPieSeries(); | |
45 | m_pie->add(1.1, "1"); |
|
45 | m_pie->add(1.1, "1"); | |
46 | m_pie->add(2.1, "2"); |
|
46 | m_pie->add(2.1, "2"); | |
47 | m_pie->add(3.0, "3"); |
|
47 | m_pie->add(3.0, "3"); | |
48 | m_pie->setPiePosition(0.7, 0.7); |
|
48 | m_pie->setPiePosition(0.7, 0.7); | |
49 | m_pie->setPieSize(0.5); |
|
49 | m_pie->setPieSize(0.5); | |
50 | m_chartView->addSeries(m_pie); |
|
50 | m_chartView->addSeries(m_pie); | |
51 |
|
51 | |||
52 | connect(&m_timer, SIGNAL(timeout()), this, SLOT(customize())); |
|
52 | connect(&m_timer, SIGNAL(timeout()), this, SLOT(customize())); | |
53 | m_timer.setInterval(1500); |
|
53 | m_timer.setInterval(1500); | |
54 | m_timer.setSingleShot(false); |
|
54 | m_timer.setSingleShot(false); | |
55 | m_timer.start(); |
|
55 | m_timer.start(); | |
56 | } |
|
56 | } | |
57 |
|
57 | |||
58 | MainWindow::~MainWindow() |
|
58 | MainWindow::~MainWindow() | |
59 | { |
|
59 | { | |
60 | } |
|
60 | } | |
61 |
|
61 | |||
62 | void MainWindow::customize() |
|
62 | void MainWindow::customize() | |
63 | { |
|
63 | { | |
64 | // Customize chart background |
|
64 | //! [1] | |
65 | // Use a gradient from color 3 to color 4 for chart background |
|
65 | // Use a gradient from "color 3" to "color 4" for chart background | |
66 | QLinearGradient chartGradient(0, 0, 0, 300); |
|
66 | QLinearGradient chartGradient(0, 0, 0, 300); | |
67 | chartGradient.setColorAt(0.0, m_companyColor3); |
|
67 | chartGradient.setColorAt(0.0, m_companyColor3); | |
68 | chartGradient.setColorAt(0.5, m_companyColor4); |
|
68 | chartGradient.setColorAt(0.5, m_companyColor4); | |
69 | chartGradient.setColorAt(1.0, m_companyColor3); |
|
69 | chartGradient.setColorAt(1.0, m_companyColor3); | |
70 | m_chartView->setChartBackgroundBrush(chartGradient); |
|
70 | m_chartView->setChartBackgroundBrush(chartGradient); | |
71 | m_chartView->setBackgroundBrush(m_companyColor4); |
|
71 | m_chartView->setBackgroundBrush(m_companyColor4); | |
72 | m_chartView->setChartTitleBrush(m_companyColor1); |
|
72 | m_chartView->setChartTitleBrush(m_companyColor1); | |
|
73 | //! [1] | |||
73 |
|
74 | |||
74 | // Customize chart axis |
|
75 | //! [2] | |
75 | QPen color1Pen(m_companyColor1, 4.0); |
|
76 | QPen color1Pen(m_companyColor1, 4.0); | |
76 | m_chartView->axisX()->setAxisPen(color1Pen); |
|
77 | m_chartView->axisX()->setAxisPen(color1Pen); | |
77 | m_chartView->axisY()->setAxisPen(color1Pen); |
|
78 | m_chartView->axisY()->setAxisPen(color1Pen); | |
|
79 | //! [2] | |||
78 |
|
80 | |||
79 | // Customize series |
|
81 | //! [3] | |
|
82 | // Customize pen of the line series | |||
80 | m_line->setPen(color1Pen); |
|
83 | m_line->setPen(color1Pen); | |
|
84 | ||||
|
85 | // Customize pen and brush for the scatter | |||
81 | m_scatter->setPen(color1Pen); |
|
86 | m_scatter->setPen(color1Pen); | |
82 | m_scatter->setBrush(m_companyColor3); |
|
87 | m_scatter->setBrush(m_companyColor3); | |
|
88 | ||||
|
89 | // Customize pen and brush for the pie | |||
83 | for (int i(0); i < m_pie->slices().count(); i++) { |
|
90 | for (int i(0); i < m_pie->slices().count(); i++) { | |
84 | Qt::BrushStyle style = static_cast<Qt::BrushStyle>(i + 1); |
|
91 | Qt::BrushStyle style = static_cast<Qt::BrushStyle>(i + 1); | |
85 | m_pie->slices().at(i)->setSliceBrush(QBrush(m_companyColor2, style)); |
|
92 | m_pie->slices().at(i)->setSliceBrush(QBrush(m_companyColor2, style)); | |
86 | m_pie->slices().at(i)->setSlicePen(color1Pen); |
|
93 | m_pie->slices().at(i)->setSlicePen(color1Pen); | |
87 | } |
|
94 | } | |
88 |
|
95 | //! [3] | ||
89 |
|
96 | |||
90 | // Calculate new colors to be used on the next update for the series |
|
97 | // Calculate new colors to be used on the next update for the series | |
91 | m_companyColor1.setRed((m_companyColor1.red() + 25) % 255); |
|
98 | m_companyColor1.setRed((m_companyColor1.red() + 25) % 255); | |
92 | m_companyColor1.setGreen((m_companyColor1.green() + 25) % 255); |
|
99 | m_companyColor1.setGreen((m_companyColor1.green() + 25) % 255); | |
93 | m_companyColor1.setBlue((m_companyColor1.blue() + 25) % 255); |
|
100 | m_companyColor1.setBlue((m_companyColor1.blue() + 25) % 255); | |
94 | m_companyColor2.setRed((m_companyColor2.red() + 25) % 255); |
|
101 | m_companyColor2.setRed((m_companyColor2.red() + 25) % 255); | |
95 | m_companyColor2.setGreen((m_companyColor2.green() + 25) % 255); |
|
102 | m_companyColor2.setGreen((m_companyColor2.green() + 25) % 255); | |
96 | m_companyColor2.setBlue((m_companyColor2.blue() + 25) % 255); |
|
103 | m_companyColor2.setBlue((m_companyColor2.blue() + 25) % 255); | |
97 | } |
|
104 | } |
General Comments 0
You need to be logged in to leave comments.
Login now