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. QDateTimeAxis - multiple series?
Forum Updated to NodeBB v4.3 + New Features

QDateTimeAxis - multiple series?

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 3.2k 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.
  • qtyetiQ Offline
    qtyetiQ Offline
    qtyeti
    wrote on last edited by
    #1

    Hi, I'm wondering if it is possible to display multiple series with QDateTimeAxis. Example: Three series for 2016 with different dates and values (all within 2016).
    Tried to attach axis to series, but only the first one is displayed.
    Let me know if my question is not clear....

    raven-worxR 1 Reply Last reply
    0
    • qtyetiQ qtyeti

      Hi, I'm wondering if it is possible to display multiple series with QDateTimeAxis. Example: Three series for 2016 with different dates and values (all within 2016).
      Tried to attach axis to series, but only the first one is displayed.
      Let me know if my question is not clear....

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      @qtyeti said:

      Tried to attach axis to series, but only the first one is displayed.

      without code we can just guess whats going wrong in there

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • qtyetiQ Offline
        qtyetiQ Offline
        qtyeti
        wrote on last edited by
        #3

        Code looks like this (adapted from examples):
        QLineSeries *series = new QLineSeries;

        QDateTime xValue;
        xValue.setDate(QDate(2012, 1, 18));
        xValue.setTime(QTime(0, 00));
        qreal yValue = 12;
        series->append(xValue.toMSecsSinceEpoch(), yValue);
        
        xValue.setDate(QDate(2013, 5, 11));
        xValue.setTime(QTime(0, 00));
        yValue = 22;
        series->append(xValue.toMSecsSinceEpoch(), yValue);
        
        xValue.setDate(QDate(2013, 6, 11));
        xValue.setTime(QTime(0, 00));
        yValue = 20;
        series->append(xValue.toMSecsSinceEpoch(), yValue);
        
        QLineSeries *series2 = new QLineSeries;
        
        xValue.setDate(QDate(2012, 2, 18));
        xValue.setTime(QTime(0, 00));
        yValue = 22;
        series2->append(xValue.toMSecsSinceEpoch(), yValue);
        
        xValue.setDate(QDate(2013, 6, 11));
        xValue.setTime(QTime(0, 00));
        yValue = 32;
        series2->append(xValue.toMSecsSinceEpoch(), yValue);
        
        xValue.setDate(QDate(2013, 7, 11));
        xValue.setTime(QTime(0, 00));
        yValue = 30;
        series2->append(xValue.toMSecsSinceEpoch(), yValue);
        
        QChart *chart = new QChart;
        chart->addSeries(series2);
        chart->addSeries(series);
        
        chart->legend()->hide();
        chart->setTitle("Test QDateTimeAxis)");
        
        QDateTimeAxis *axisX = new QDateTimeAxis;
        axisX->setFormat("dd-MM-yyyy h:mm");
        axisX->setTickCount(1);
        axisX->setTitleText("Date");
        chart->addAxis(axisX, Qt::AlignBottom);
        
        series2->attachAxis(axisX);
        series->attachAxis(axisX);
        QValueAxis *axisY = new QValueAxis;
        axisY->setLabelFormat("%i");
        axisY->setTitleText("Test Axis");
        chart->addAxis(axisY, Qt::AlignLeft);
        series2->attachAxis(axisY);
        series->attachAxis(axisY);
        
        Test2Qt w;
        
        QChartView *chartView = new QChartView(chart);
        chartView->setRenderHint(QPainter::Antialiasing);
        w.setCentralWidget(chartView);
        w.resize(820, 600);
        w.show();
        
        raven-worxR 1 Reply Last reply
        0
        • qtyetiQ qtyeti

          Code looks like this (adapted from examples):
          QLineSeries *series = new QLineSeries;

          QDateTime xValue;
          xValue.setDate(QDate(2012, 1, 18));
          xValue.setTime(QTime(0, 00));
          qreal yValue = 12;
          series->append(xValue.toMSecsSinceEpoch(), yValue);
          
          xValue.setDate(QDate(2013, 5, 11));
          xValue.setTime(QTime(0, 00));
          yValue = 22;
          series->append(xValue.toMSecsSinceEpoch(), yValue);
          
          xValue.setDate(QDate(2013, 6, 11));
          xValue.setTime(QTime(0, 00));
          yValue = 20;
          series->append(xValue.toMSecsSinceEpoch(), yValue);
          
          QLineSeries *series2 = new QLineSeries;
          
          xValue.setDate(QDate(2012, 2, 18));
          xValue.setTime(QTime(0, 00));
          yValue = 22;
          series2->append(xValue.toMSecsSinceEpoch(), yValue);
          
          xValue.setDate(QDate(2013, 6, 11));
          xValue.setTime(QTime(0, 00));
          yValue = 32;
          series2->append(xValue.toMSecsSinceEpoch(), yValue);
          
          xValue.setDate(QDate(2013, 7, 11));
          xValue.setTime(QTime(0, 00));
          yValue = 30;
          series2->append(xValue.toMSecsSinceEpoch(), yValue);
          
          QChart *chart = new QChart;
          chart->addSeries(series2);
          chart->addSeries(series);
          
          chart->legend()->hide();
          chart->setTitle("Test QDateTimeAxis)");
          
          QDateTimeAxis *axisX = new QDateTimeAxis;
          axisX->setFormat("dd-MM-yyyy h:mm");
          axisX->setTickCount(1);
          axisX->setTitleText("Date");
          chart->addAxis(axisX, Qt::AlignBottom);
          
          series2->attachAxis(axisX);
          series->attachAxis(axisX);
          QValueAxis *axisY = new QValueAxis;
          axisY->setLabelFormat("%i");
          axisY->setTitleText("Test Axis");
          chart->addAxis(axisY, Qt::AlignLeft);
          series2->attachAxis(axisY);
          series->attachAxis(axisY);
          
          Test2Qt w;
          
          QChartView *chartView = new QChartView(chart);
          chartView->setRenderHint(QPainter::Antialiasing);
          w.setCentralWidget(chartView);
          w.resize(820, 600);
          w.show();
          
          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @qtyeti
          what do the attachAxis() calls return?
          Any warnings in the console?

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • qtyetiQ Offline
            qtyetiQ Offline
            qtyeti
            wrote on last edited by
            #5

            attachAxis both return "TRUE"...
            No warnings in the console.
            Maybe it's not possible to do that at all?

            1 Reply Last reply
            0
            • qtyetiQ Offline
              qtyetiQ Offline
              qtyeti
              wrote on last edited by
              #6

              Problem fixed - was an issue with the min/max of the value axis.

              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