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 not rendering labels when manually setting range
Forum Updated to NodeBB v4.3 + New Features

QDateTimeAxis not rendering labels when manually setting range

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 1 Posters 844 Views
  • 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.
  • BarronjB Offline
    BarronjB Offline
    Barronj
    wrote on last edited by
    #1

    Hello,

    I'm trying QCharts for the first time using version 5.7 that I compiled on a CentOS 7 machine. There are several time series that contain different time periods that should share both the X and Y axes. I tried to attach each axis to all the series, but that just had the plot adjust to one series instead of zoom fitting to show them all. This was a problem for both the X and Y axes. So then I tried to set the range for each axis, but the QDateTimeAxis then doesn't render. The Y axis renders fine, though.

    Here is some example code:

    void Plot::beginPlotting() {
        chart()->removeAllSeries();
    
        if (axisX != nullptr) {
            chart()->removeAxis(axisX);
            axisX->deleteLater();
            axisX = nullptr;
        }
    
        if (axisY != nullptr) {
            chart()->removeAxis(axisY);
            axisY->deleteLater();
            axisY = nullptr;
        }
    
        series    = nullptr;
        boundsSet = false;
    }
    
    void Plot::beginSeries() {
        if (series != nullptr) {
            chart()->addSeries(series);
        }
    
        series = new QLineSeries;
    
        QPen pen(QRgb(0x00B2EE));
        series->setPen(pen);
    }
    
    void Plot::addPoint(qint64 time, double value) {
        if (series != nullptr) {
            time *= 1000;
            series->append(time, value);
    
            if (!boundsSet) {
                minVal    = value;
                maxVal    = value;
                minTime   = time;
                maxTime   = time;
                boundsSet = true;
            }
            else {
                if (minTime > time) { minTime = time; }
                if (maxTime < time) { maxTime = time; }
                if (minVal > value) { minVal = value; }
                if (maxVal < value) { maxVal = value; }
            }
        }
    }
    
    void Plot::endPlotting() {
        if (series != nullptr) {
            chart()->addSeries(series);
            series = nullptr;
        }
    
        axisX = new QDateTimeAxis;
        axisX->setTickCount(10);
        axisX->setFormat("hh:mm:ss");
        axisX->setTitleText("Date");
    
        chart()->addAxis(axisX, Qt::AlignBottom);
    
        axisY = new QValueAxis;
        axisY->setLabelFormat("%3.1lf");
        axisY->setTitleText("Value");
    
        chart()->addAxis(axisY, Qt::AlignLeft);
    
        /*
        foreach (QAbstractSeries *series, chart()->series()) {
            series->attachAxis(axisX);
            series->attachAxis(axisY);
        }
        */
    
        if (boundsSet) {
            QDateTime min, max;
    
            min.setMSecsSinceEpoch(minTime);
            max.setMSecsSinceEpoch(minTime);
            axisX->setRange(min, max);
            axisY->setRange(minVal, maxVal);
        }
    }
    
    1 Reply Last reply
    0
    • BarronjB Offline
      BarronjB Offline
      Barronj
      wrote on last edited by Barronj
      #2

      Found the error. Used minTime to set both min and max. Sorry to bother you with my stupid mistake.

      1 Reply Last reply
      1

      • Login

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