Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Decimals in labels on an axis of a QChart[View]



  • I have a QLineSeries/QChart displayed in a QChartView. Even though the points I've added are whole numbers, the display graph shows decimals point along the X/Y axes. How do I turn off the decimals points, i.e., specify 0 decimals?



  • You can use format specifiers, have a look at the following example from Qt documentation.

      QChartView *chartView = new QChartView;
      QLineSeries *series = new QLineSeries;
      // ...
      chartView->chart()->addSeries(series);
    
      QValueAxis *axisX = new QValueAxis;
      axisX->setRange(10, 20.5);
      axisX->setTickCount(10);
      axisX->setLabelFormat("%.2f");
      chartView->chart()->setAxisX(axisX, series);
    
    

Log in to reply