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 refresh, with new call chart function, that add chart but not delete the first one...
Forum Updated to NodeBB v4.3 + New Features

QChart refresh, with new call chart function, that add chart but not delete the first one...

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 344 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.
  • F Offline
    F Offline
    filipdns
    wrote on last edited by
    #1

    Hello, How can I have dynamic update of my chart?
    I try chartView.update, chartView.repaint, chart.removeAllSeries but nothing work

    here the code:

        QFile fileGraph("d:/Magasin_Temp_Hygro2.txt");//select text file with recorded data
        fileGraph.open(QFile::ReadOnly);//open text file with recorded data
        int line_count=0;
        qreal temp=0;
        QString date;
        qreal hygro;
        QLineSeries *temperature = new QLineSeries();
        QLineSeries *hygrometrie = new QLineSeries();
        QCategoryAxis *axisX = new QCategoryAxis;
        QCategoryAxis *axisY1 = new QCategoryAxis;
        QCategoryAxis *axisY = new QCategoryAxis;
        while( !fileGraph.atEnd())//loop until end of QTextStrem
        {
            QString line=fileGraph.readLine();
            QString date=line.split(":")[0];
            bool ok = false;
            temp=line.split(":")[2].toDouble(&ok);
            hygro=line.split(":")[4].replace(";","").toDouble(&ok);
            axisX->append(date,line_count);
            axisY1->append(QString::number(temp),temp);
            axisY->append(QString::number(hygro),hygro);
            *temperature <<QPointF(line_count, temp);
            *hygrometrie <<QPointF(line_count, hygro);
            line_count++;
        }
    
        chart->addSeries(temperature);
        chart->addSeries(hygrometrie);
        temperature->attachAxis(axisX);
        temperature->attachAxis(axisY1);
        hygrometrie->attachAxis(axisY);
        axisX->setLabelsAngle(-90);
        axisX->setLabelsPosition(QCategoryAxis::AxisLabelsPositionOnValue);
        axisY1->setLabelsPosition(QCategoryAxis::AxisLabelsPositionOnValue);
        axisY1->setMin(10);
        axisY1->setMax(100);
        axisY1->setLabelsColor(temperature->pen().color());
        axisY->setLabelsPosition(QCategoryAxis::AxisLabelsPositionOnValue);
        axisY->setMin(10);
        axisY->setMax(100);
        axisY->setLabelsColor(hygrometrie->pen().color());
        chart->addAxis(axisY, Qt::AlignRight);
        chart->addAxis(axisY1, Qt::AlignLeft);
        chart->addAxis(axisX, Qt::AlignBottom);
        chart->setTitle("Revelé Température et humidité Magasin");
        chartView->setRenderHint(QPainter::Antialiasing);
        chartView->chart()->setAxisX(axisX, hygrometrie);
        chartView->chart()->setAxisY(axisY, hygrometrie);
        chartView->chart()->setAxisX(axisY1, temperature);
        fileGraph.close();
    

    here the result:

    0_1557124193426_multiplecharts.png

    Thank you for your help

    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