Hello Everybody,
I'd like to add some describing text to a given QPointF on a chart. I really spent a lot of time trying all of the mapToX's and mapFromX's to map coordinates.
Here's a short wrap up about what I'm doing:
// create Chart
chart = new QChart();
chart->createDefaultAxes();
// costumize chart
dateTimeAxis = new QDateTimeAxis;
categoryAxis = new QBarCategoryAxis();
categoryAxis->append(categoriesList);
chart->addAxis(dateTimeAxis,Qt::AlignBottom);
chart->addAxis(categoryAxis, Qt::AlignLeft);
// hide casual axes
chart->axisX()->hide();
chart->axisY()->hide();
// use QChartView
myChartView = new QChartView(chart);
// promote to QMainWindow
layout->addWidget(myChartView);
myWidget->setLayout(layout);
setCentralWidget(myWidget);
///////////////////
// generate some life
lowerSeries = new QLineSeries();
upperSeries = new QLineSeries();
area = new QAreaSeries(upperSeries, lowerSeries);
area->attachAxis(dateTimeAxis);
area->attachAxis(chart->axisY());
p2
= QPointF(QDateTime::currentTime.
addSecs(rand_N_ofSec
).
toMSecsSinceEpoch(),
1);
p4
= QPointF(QDateTime::currentTime.
addSecs(rand_N_ofSec
).
toMSecsSinceEpoch(),
5);
lowerSeries << p1 << p2;
upperSeries << p3 << p4;
// now the problem:
tag->setText("any text to describe the point");
// how toset the location of the tag properly (near the point)?
// create Chart
chart = new QChart();
chart->createDefaultAxes();
// costumize chart
dateTimeAxis = new QDateTimeAxis;
categoryAxis = new QBarCategoryAxis();
categoryAxis->append(categoriesList);
chart->addAxis(dateTimeAxis,Qt::AlignBottom);
chart->addAxis(categoryAxis, Qt::AlignLeft);
// hide casual axes
chart->axisX()->hide();
chart->axisY()->hide();
// use QChartView
myChartView = new QChartView(chart);
// promote to QMainWindow
layout->addWidget(myChartView);
myWidget = new QWidget();
myWidget->setLayout(layout);
setCentralWidget(myWidget);
///////////////////
// generate some life
lowerSeries = new QLineSeries();
upperSeries = new QLineSeries();
area = new QAreaSeries(upperSeries, lowerSeries);
area->attachAxis(dateTimeAxis);
area->attachAxis(chart->axisY());
p1 = QPointF(QDateTime::currentTime.toMSecsSinceEpoch(), 1);
p3 = QPointF(QDateTime::currentTime.toMSecsSinceEpoch(), 5);
p2 = QPointF(QDateTime::currentTime.addSecs(rand_N_ofSec).toMSecsSinceEpoch(), 1);
p4 = QPointF(QDateTime::currentTime.addSecs(rand_N_ofSec).toMSecsSinceEpoch(), 5);
lowerSeries << p1 << p2;
upperSeries << p3 << p4;
// now the problem:
tag = new QGraphicsSimpleTextItem(chart);
tag->setText("any text to describe the point");
// how toset the location of the tag properly (near the point)?
To copy to clipboard, switch view to plain text mode
i.e. the point is at (30,60) I'd like to set the tag on (31,61)
a typical QPointF on the chart would look like
qDebug() << "p:" << p;
p
: QPointF(1.51138e
+12,
3) // strange numbers due to toMSecSinceEpoche()
p1 = QPointF(QDateTime::currentTime.toMSecsSinceEpoch(), 3);
qDebug() << "p:" << p;
p: QPointF(1.51138e+12, 3) // strange numbers due to toMSecSinceEpoche()
To copy to clipboard, switch view to plain text mode
Thanks in advance, Lars
Bookmarks