Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Data labels in linechart Qt Charts

Tags:

c++11

qt

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

like image 348
Sam1324 Avatar asked Jun 27 '17 13:06

Sam1324


1 Answers

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");
like image 84
Fritz Avatar answered Oct 14 '22 09:10

Fritz