I am trying to add data labels in LineChart using Qt Charts like this Image.
I am not able to figure out how I can do that. Any help will be appreciated.
I am using this example https://doc.qt.io/qt-5/qtcharts-linechart-example.html
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QLineSeries *series = new QLineSeries();
series->append(0, 6);
series->append(2, 4);
series->append(3, 8);
series->append(7, 4);
series->append(10, 5);
QChart *chart = new QChart();
chart->legend()->hide();
chart->addSeries(series);
chart->createDefaultAxes();
chart->setTitle("Simple line chart example");
QChartView *chartView = new QChartView(chart);
chartView->setRenderHint(QPainter::Antialiasing);
QMainWindow window;
window.setCentralWidget(chartView);
window.resize(400, 300);
window.show();
return a.exec();
}
I get following output
I want something like this
Have you tried to set the labels to visible?
QLineSeries *series = new QLineSeries();
series->setPointLabelsVisible(true); // is false by default
series->setPointLabelsColor(Qt::black);
series->setPointLabelsFormat("@yPoint");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With