Adjusting axis according to coming datas
Unsolved
General and Desktop
-
I have a scrolling dynamic chart. When the new data come, i cannot see because the chart size. Can i automatize it ? Does qt charts have a property like that?
#include "mainwindow.h" #include "ui_mainwindow.h" #include <QFile> #include <QtCharts/QLineSeries> #include <QTimer> #include <QTextStream> #include <QtCharts> #include <QChart> #include <QString> #include <QStringList> #include <QtCore/QDateTime> #include <QtCharts/QDateTimeAxis> #include <QQueue> QT_CHARTS_USE_NAMESPACE using namespace QtCharts; MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); initChartView(); ReadFile(); connect(m_timer, SIGNAL(timeout()), SLOT(Timer_Slot())); m_timer->setInterval(500); m_timer->start(); } void MainWindow::Timer_Slot() { static float q_x=0; if(!queue.isEmpty()) { double num=queue.dequeue(); q_x += 0.1; series->append(q_x, num); chart->update(); qDebug() << q_x << num; } } MainWindow::~MainWindow() { delete ui; } void MainWindow::ReadFile() { QFile file("C:/Users/ilknu/Documents/untitled1/deneme.txt"); if (file.open(QIODevice::ReadOnly)) { QTextStream in (&file); while (!in.atEnd()) { QString line = in.readLine(); QStringList list = line.split(QLatin1Char(' '), Qt::SkipEmptyParts); for(const QString &entry : list) { double num = entry.toDouble(); qDebug()<<num; queue.enqueue(num); } // for } // while } // if file.close(); } void MainWindow::initChartView() { QChart *chart = new QChart(); chart->addSeries(series); qDebug()<< series; QPen green(Qt::red); green.setWidth(2); series->setPen(green); chart->legend()->hide(); chart->setTitle("deneme"); chart->setAnimationOptions(QChart::AllAnimations); QValueAxis *axisX=new QValueAxis; axisX->setTickCount(10); axisX->setRange(0,2); chart->addAxis(axisX, Qt::AlignBottom); series->attachAxis(axisX); QValueAxis *axisY = new QValueAxis; axisY->setTickCount(5); axisY->setRange(0,2); chart->addAxis(axisY, Qt::AlignLeft); series->attachAxis(axisY); QChartView *chartView = new QChartView(chart); chartView->setRenderHint(QPainter::Antialiasing); this->setCentralWidget(chartView); }