Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QChart axisX actualized DateTime

QChart axisX actualized DateTime

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 1.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Milori
    wrote on last edited by
    #1

    Hi,
    axisX shows 08:21 18.01.70 only, I would to show actualized DT on axisX. axisY Value type work properly, code:

    QLineSeries *sData = new QLineSeries();
    QDateTime actualDateTime =  QDateTime::currentDateTime();
    sData->append(actualDateTime.toSecsSinceEpoch(),tepl01.toFloat());//toMsecSinceEpoch() do overflow variable and shows nothing
    
    QChart *tempChart = new QChart();
    tempChart->addSeries(sData);
    tempChart->legend()->hide();
    tempChart->setTitle("Ser data");
    tempChart->createDefaultAxes();//not work without this
    
    QDateTimeAxis *axisX = new QDateTimeAxis;
    //axisX->setTickCount(10);
    axisX->setFormat("hh:mm dd.MMM.yy");
    axisX->setTitleText("Datum");
    //tempChart->addAxis(axisX, Qt::AlignBottom);//shows seconds from epoch only, not DateTime format
    tempChart->setAxisX(axisX, sData);
    
    QValueAxis *axisY = new QValueAxis;
    axisY->setLabelFormat("%.1f");
    axisY->setTitleText("Serial data");
    

    // tempChart->addAxis(axisY, Qt::AlignLeft);
    tempChart->setAxisY(axisY, sData);

    QChartView *showChart = new QChartView(tempChart);
    setCentralWidget(showChart);
    showChart->setRenderHint(QPainter::Antialiasing);
    

    Is problem overflowing q64 due big toMsecSinceEpoch() or...?
    thx

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Hi!
      There's a typo in your code, should be toMSecsSinceEpoch, not toSecsSinceEpoch:

      sData->append(actualDateTime.toSecsSinceEpoch(),tepl01.toFloat());

      Have a look at the DateTimeAxis Example.

      1 Reply Last reply
      1
      • M Offline
        M Offline
        Milori
        wrote on last edited by
        #3

        Hi,
        code above is in periodically called method void MainWindow::serialData() in file mainwindow.cpp I researched that mentioned problem is probably caused by leaving this method and code entering to main method to show window. Object QChartView maybe corrupted or destructed. Creating window object and show it: MainWindow w;
        w.show(); from this method not work.
        How to show main window from this method or how to solve this situation?

        1 Reply Last reply
        0
        • Z Offline
          Z Offline
          Zeeshan Mehmood
          wrote on last edited by
          #4

          I had similar problem with toMSecssinceEpoch() method. The ChartView does not show plotted points. I changed it to toSecsSinceEpoch() and QDatetimeAxis is shown in ChartView. Thanks.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved