Setting size of QBoxPlot horizontal axis slot.
-
How do you set size of QBoxPlot horizontal axis slot so that there's enough space for each slot to fully show axis value, and scrollbar is generated where total size of all the slots exceed the chartview size? Or, how do you control number of box sets on display in the chartview (if the total number of box sets overflows then scrollbar is generated, like this example http://www.advsofteng.com/doc/cdcppdoc/zoomscrolltrackqt.htm)?
#include "mainwindow.h" #include "ui_mainwindow.h" #include <QChartView> #include <QBoxPlotSeries> #include <QBoxSet> #include <QValueAxis> #include <QBarCategoryAxis> #include <QtSql> #include <QSqlDatabase> #include <QSqlQuery> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL"); db.setHostName("192.168.2.103"); db.setPort(5433); db.setUserName("vorlket"); db.setPassword("K1156312j"); db.setDatabaseName("fxproj"); QBoxPlotSeries *bidaskSeries = new QBoxPlotSeries(this); bidaskSeries->setName("bidask"); QStringList categories; if (db.open()) { QSqlQuery query; if (query.exec("SELECT EXTRACT(YEAR FROM month), EXTRACT(MONTH FROM month), bid_low, bid_lowquartile, bid_median, bid_upquartile, bid_high FROM audusd.ts_month_quotebid ORDER BY month")) { while (query.next()) { categories << query.value(0).toString() + "-" + query.value(1).toString(); QBoxSet *set = new QBoxSet(); set->setValue(QBoxSet::LowerExtreme, query.value(2).toDouble()); set->setValue(QBoxSet::LowerQuartile, query.value(3).toDouble()); set->setValue(QBoxSet::Median, query.value(4).toDouble()); set->setValue(QBoxSet::UpperQuartile, query.value(5).toDouble()); set->setValue(QBoxSet::UpperExtreme, query.value(6).toDouble()); bidaskSeries->append(set); } } db.close(); } QChart *chart = new QChart(); chart->legend()->hide(); chart->addSeries(bidaskSeries); QBarCategoryAxis * axisX = new QBarCategoryAxis(); axisX->append(categories); chart->addAxis(axisX, Qt::AlignBottom); chart->setAxisX(axisX, bidaskSeries); QValueAxis *axisY = new QValueAxis(); chart->addAxis(axisY, Qt::AlignLeft); chart->setAxisY(axisY, bidaskSeries); axisY->setRange(0.65, 1.15); ui->chartview->setChart(chart); ui->chartview->setRenderHint(QPainter::Antialiasing); } MainWindow::~MainWindow() { delete ui; }
-
Maybe I need to use QGraphicsScene.
http://doc.qt.io/qt-5/qchartview.html#details:
QChartView is a standalone widget that can display charts. It does not require separate QGraphicsScene to work. If you want to display a chart in your existing QGraphicsScene, you need to use the QChart (or QPolarChart) class instead.
http://doc.qt.io/qt-5/qgraphicsscene.html#details:
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items.
The class serves as a container for QGraphicsItems. It is used together with QGraphicsView for visualizing graphical items, such as lines, rectangles, text, or even custom items, on a 2D surface. QGraphicsScene is part of the Graphics View Framework.
QGraphicsScene also provides functionality that lets you efficiently determine both the location of items, and for determining what items are visible within an arbitrary area on the scene. With the QGraphicsView widget, you can either visualize the whole scene, or zoom in and view only parts of the scene.