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. Adjusting axis according to coming datas
Forum Updated to NodeBB v4.3 + New Features

Adjusting axis according to coming datas

Scheduled Pinned Locked Moved Unsolved General and Desktop
chartaxis qchartqt5
1 Posts 1 Posters 261 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.
  • D Offline
    D Offline
    deleted286
    wrote on 7 Jan 2021, 07:30 last edited by
    #1

    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? Ekran görüntüsü 2021-01-06 171507.png

    #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);
    }
    
    1 Reply Last reply
    0

    1/1

    7 Jan 2021, 07:30

    • Login

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