main.cpp
131 lines
| 3.8 KiB
| text/x-c
|
CppLexer
Michal Klocek
|
r747 | /**************************************************************************** | ||
** | ||||
Miikka Heikkinen
|
r2433 | ** Copyright (C) 2013 Digia Plc | ||
Michal Klocek
|
r747 | ** All rights reserved. | ||
** For any questions to Digia, please use contact form at http://qt.digia.com | ||||
** | ||||
** This file is part of the Qt Commercial Charts Add-on. | ||||
** | ||||
Jani Honkonen
|
r830 | ** $QT_BEGIN_LICENSE$ | ||
** Licensees holding valid Qt Commercial licenses may use this file in | ||||
** accordance with the Qt Commercial License Agreement provided with the | ||||
** Software or, alternatively, in accordance with the terms contained in | ||||
** a written agreement between you and Digia. | ||||
Michal Klocek
|
r747 | ** | ||
Jani Honkonen
|
r830 | ** If you have questions regarding the use of this file, please use | ||
** contact form at http://qt.digia.com | ||||
Michal Klocek
|
r747 | ** $QT_END_LICENSE$ | ||
** | ||||
****************************************************************************/ | ||||
Michal Klocek
|
r69 | #include <QApplication> | ||
#include <QMainWindow> | ||||
Michal Klocek
|
r747 | #include <QChartView> | ||
#include <QLineSeries> | ||||
Marek Rosa
|
r1816 | #include <QCategoryAxis> | ||
Michal Klocek
|
r69 | |||
QTCOMMERCIALCHART_USE_NAMESPACE | ||||
int main(int argc, char *argv[]) | ||||
{ | ||||
QApplication a(argc, argv); | ||||
Michal Klocek
|
r747 | //![1] | ||
Jani Honkonen
|
r2102 | QLineSeries *series = new QLineSeries(); | ||
Marek Rosa
|
r1712 | *series << QPointF(0, 6) << QPointF(9, 4) << QPointF(15, 20) << QPointF(25, 12) << QPointF(29, 26); | ||
Jani Honkonen
|
r2102 | QChart *chart = new QChart(); | ||
Jani Honkonen
|
r1400 | chart->legend()->hide(); | ||
Michal Klocek
|
r747 | chart->addSeries(series); | ||
Tero Ahola
|
r942 | //![1] | ||
Jani Honkonen
|
r883 | |||
Tero Ahola
|
r942 | //![2] | ||
// Customize series | ||||
QPen pen(QRgb(0xfdb157)); | ||||
pen.setWidth(5); | ||||
series->setPen(pen); | ||||
// Customize chart title | ||||
Michal Klocek
|
r192 | QFont font; | ||
font.setPixelSize(18); | ||||
Michal Klocek
|
r747 | chart->setTitleFont(font); | ||
Tero Ahola
|
r942 | chart->setTitleBrush(QBrush(Qt::white)); | ||
chart->setTitle("Customchart example"); | ||||
Michal Klocek
|
r122 | |||
Tero Ahola
|
r942 | // Customize chart background | ||
Michal Klocek
|
r122 | QLinearGradient backgroundGradient; | ||
Jani Honkonen
|
r2098 | backgroundGradient.setStart(QPointF(0, 0)); | ||
backgroundGradient.setFinalStop(QPointF(0, 1)); | ||||
Tero Ahola
|
r942 | backgroundGradient.setColorAt(0.0, QRgb(0xd2d0d1)); | ||
backgroundGradient.setColorAt(1.0, QRgb(0x4c4547)); | ||||
Michal Klocek
|
r122 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | ||
Michal Klocek
|
r747 | chart->setBackgroundBrush(backgroundGradient); | ||
Miikka Heikkinen
|
r2502 | |||
// Customize plot area background | ||||
QLinearGradient plotAreaGradient; | ||||
plotAreaGradient.setStart(QPointF(0, 1)); | ||||
plotAreaGradient.setFinalStop(QPointF(1, 0)); | ||||
plotAreaGradient.setColorAt(0.0, QRgb(0x555555)); | ||||
plotAreaGradient.setColorAt(1.0, QRgb(0x55aa55)); | ||||
plotAreaGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | ||||
chart->setPlotAreaBackgroundBrush(plotAreaGradient); | ||||
chart->setPlotAreaBackgroundVisible(true); | ||||
Tero Ahola
|
r942 | //![2] | ||
Jani Honkonen
|
r883 | |||
Tero Ahola
|
r942 | //![3] | ||
Jani Honkonen
|
r2102 | QCategoryAxis *axisX = new QCategoryAxis(); | ||
QCategoryAxis *axisY = new QCategoryAxis(); | ||||
Michal Klocek
|
r767 | |||
Tero Ahola
|
r942 | // Customize axis label font | ||
QFont labelsFont; | ||||
labelsFont.setPixelSize(12); | ||||
axisX->setLabelsFont(labelsFont); | ||||
axisY->setLabelsFont(labelsFont); | ||||
// Customize axis colors | ||||
QPen axisPen(QRgb(0xd18952)); | ||||
axisPen.setWidth(2); | ||||
Marek Rosa
|
r1844 | axisX->setLinePen(axisPen); | ||
axisY->setLinePen(axisPen); | ||||
Tero Ahola
|
r942 | |||
// Customize axis label colors | ||||
QBrush axisBrush(Qt::white); | ||||
axisX->setLabelsBrush(axisBrush); | ||||
axisY->setLabelsBrush(axisBrush); | ||||
// Customize grid lines and shades | ||||
Michal Klocek
|
r767 | axisX->setGridLineVisible(false); | ||
axisY->setGridLineVisible(false); | ||||
axisY->setShadesPen(Qt::NoPen); | ||||
Miikka Heikkinen
|
r2502 | axisY->setShadesBrush(QBrush(QColor(0x99, 0xcc, 0xcc, 0x55))); | ||
Michal Klocek
|
r767 | axisY->setShadesVisible(true); | ||
Tero Ahola
|
r942 | //![3] | ||
Jani Honkonen
|
r883 | |||
Tero Ahola
|
r942 | //![4] | ||
Marek Rosa
|
r1702 | axisX->append("low", 10); | ||
axisX->append("optimal", 20); | ||||
axisX->append("high", 30); | ||||
axisX->setRange(0, 30); | ||||
axisY->append("slow", 10); | ||||
axisY->append("med", 20); | ||||
axisY->append("fast", 30); | ||||
axisY->setRange(0, 30); | ||||
Michal Klocek
|
r1655 | |||
Marek Rosa
|
r1647 | chart->setAxisX(axisX, series); | ||
chart->setAxisY(axisY, series); | ||||
Tero Ahola
|
r942 | //![4] | ||
Jani Honkonen
|
r883 | |||
Tero Ahola
|
r942 | //![5] | ||
Jani Honkonen
|
r2102 | QChartView *chartView = new QChartView(chart); | ||
Michal Klocek
|
r747 | chartView->setRenderHint(QPainter::Antialiasing); | ||
Tero Ahola
|
r942 | //![5] | ||
Jani Honkonen
|
r883 | |||
Tero Ahola
|
r942 | //![6] | ||
Michal Klocek
|
r747 | QMainWindow window; | ||
Michal Klocek
|
r69 | window.setCentralWidget(chartView); | ||
window.resize(400, 300); | ||||
window.show(); | ||||
Tero Ahola
|
r942 | //![6] | ||
Jani Honkonen
|
r883 | |||
Michal Klocek
|
r69 | return a.exec(); | ||
} | ||||