Qwt Plot

Alles rund um die Programmierung mit Qt
Antworten
js
Beiträge: 59
Registriert: 4. Juli 2011 21:29

Qwt Plot

Beitrag von js »

Abend,
Versuche gerade einen realtime plot durchzuführen. Funktioniert schon ganz gut jedoch ist der erste Punkt mit dem letzten verbunden.
Wie bekomme ich das weg?
lg
Dateianhänge
plot.jpg
plot.jpg (23.66 KiB) 3054 mal betrachtet
ScyllaIllciz
Beiträge: 200
Registriert: 9. Juli 2010 19:31

Re: Qwt Plot

Beitrag von ScyllaIllciz »

Ich bin mir ziemlich sicher, dass in dem letzten Wert "0" drinnen steht ;-)
js
Beiträge: 59
Registriert: 4. Juli 2011 21:29

Re: Qwt Plot

Beitrag von js »

ne leider nicht habe es nochmal mit eigenen Werten getestet.
Er verbindet einen neuen Wert sofort mit dem aller ersten.

Code: Alles auswählen

// Die Variablen
int sx=0;
const int Size=27;
double xval[Size];
double yval[Size];

//Die plotfunktion
void tpopt::plot1()
{
xval[sx]=sx;
yval[sx]=thread1.ywertplot1; 

curve1->setSymbol(new QwtSymbol(QwtSymbol::Cross, Qt::NoBrush,
        QPen(Qt::black), QSize(5, 5) ) ); 
curve1->setPen(QColor(Qt::darkGreen));
curve1->setStyle(QwtPlotCurve::Lines);
curve1->setRawSamples(xval, yval, Size);
sx++; 
}
im Grunde ist nur der ywert wichtig der x Wert ist eine Laufvariable
ScyllaIllciz
Beiträge: 200
Registriert: 9. Juli 2010 19:31

Re: Qwt Plot

Beitrag von ScyllaIllciz »

mainwindow.h

Code: Alles auswählen

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <qwt_plot_curve.h>

const int MAX_VALUE = 10;
namespace Ui {
    class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private:
    Ui::MainWindow *ui;
    double xValue[MAX_VALUE];
    double yValue[MAX_VALUE];
    QwtPlotCurve *curve;
};

#endif // MAINWINDOW_H
mainwindow.cpp

Code: Alles auswählen

#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow),
    curve(new QwtPlotCurve)
{
    ui->setupUi(this);
    for (int i=0; i<MAX_VALUE; ++i){
        xValue[i]=i;
        yValue[i]=i;
    }

    curve->setSymbol(new QwtSymbol(QwtSymbol::Cross, Qt::NoBrush,
            QPen(Qt::black), QSize(5, 5) ) );
    curve->setPen(QColor(Qt::darkGreen));
    curve->setStyle(QwtPlotCurve::Lines);

    curve->attach(ui->qwtPlot);
    curve->setRawSamples(xValue, yValue, MAX_VALUE);
    ui->qwtPlot->replot();

}

MainWindow::~MainWindow()
{
    delete ui;
}
main.cpp

Code: Alles auswählen

#include <QtGui/QApplication>
#include "mainwindow.h"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec();
}
Funktioniert hier wie erwartet.
js
Beiträge: 59
Registriert: 4. Juli 2011 21:29

Re: Qwt Plot

Beitrag von js »

Edit: Vielen Dank für die Hilfe
Fehler gefunden.
Das Ding ist weiß nicht wie viele Werte noch kommen. Wenn Size größer ist als die Anzahl der Werte dann verbindet er es.
curve1->setRawSamples(xval, yval, sx);
sx++;
Läuft jetzt.
Antworten