Unsolved QChart refresh, with new call chart function, that add chart but not delete the first one...
-
Hello, How can I have dynamic update of my chart?
I try chartView.update, chartView.repaint, chart.removeAllSeries but nothing workhere 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:
Thank you for your help