동일한 그래프에는 세 개의 실시간 신호가 있지만 때때로 겹치기도하고 y 축을 위아래로 움직이려면 슬라이드 단추가 필요합니다. 그 (것)들 잘. 슬라이드에 그래프를 연결하려면 어떻게해야합니까? 슬라이드 값이 변경 될 때와 마찬가지로 신호의 데이터가 real_y_values + slide_value의 그래프에 추가됩니까?신호를 y 축으로 위아래로 이동시키는 Qt의 슬라이드 추가
MainWindow::MainWindow(QSerialPort* s,QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
reader(s)
{
ui->setupUi(this);
connect(ui->verticalSlider,SIGNAL(valueChanged(int)),ui->customPlot,SLOT(deplasare()));
setGeometry(400, 250, 542, 390);
grafic(ui->customPlot);
setWindowTitle("Real Time Data Graph for EDA ");
statusBar()->clearMessage();
ui->customPlot->replot();
}
void MainWindow::grafic(QCustomPlot *customPlot)
{
Graph_Name = "Real Time Data Graph for EDA";
customPlot->addGraph(); // blue line
customPlot->graph(0)->setPen(QPen(Qt::blue));
customPlot->addGraph();
customPlot->graph(1)->setPen(QPen(Qt::blue));
customPlot->addGraph(); // red line
customPlot->graph(2)->setPen(QPen(Qt::red));
customPlot->addGraph();
customPlot->graph(3)->setPen(QPen(Qt::red));
customPlot->addGraph(); // green line
customPlot->graph(4)->setPen(QPen(Qt::green));
customPlot->axisRect()->setupFullAxesBox();
connect(&dataTimer, SIGNAL(timeout()), this, SLOT(realtimeDataSlot()));
dataTimer.start(100); // Interval 0 means to refresh as fast as possible
}
void MainWindow::realtimeDataSlot()
{
timeCounter+=10;
QByteArray data1;
data1=reader._read_callback();
int sz = data1.size();
int value0;
int value2=800;
int ssz=0;
for(int ii=0;ii<sz;ii++)
if((int)data1[ii] != 13 && (int)data1[ii] != 10)
{
value0=(int)data1[ii];
ssz++;
//fct add graph
ui->customPlot->graph(0)->addData(timeCounter, value0);
buf.push(value0);
ui->customPlot->graph(2)->addData(timeCounter, buf.get_SCL());
cout<<value0<<" "<<buf.get_SCL()<<endl;
}
if(timeCounter>=800)
{
timeCounter = 0;
ui->customPlot->graph(1)->clearData();
ui->customPlot->graph(1)->addData(*(ui->customPlot->graph(0)->data()));
ui->customPlot->graph(0)->clearData();
ui->customPlot->graph(3)->clearData();
ui->customPlot->graph(3)->addData(*(ui->customPlot->graph(2)->data()));
ui->customPlot->graph(2)->clearData();
}
else {
ui->customPlot->graph(4)->addData(timeCounter, value2);
ui->customPlot->xAxis->setRange(0,800);
ui->customPlot->yAxis->setRange(-300, 1024);
}
ui->customPlot->graph(1)->removeData(timeCounter, timeCounter+50);
ui->customPlot->graph(3)->removeData(timeCounter, timeCounter+50);
ui->customPlot->replot();
}
void MainWindow::deplasare()
{
}
MainWindow::~MainWindow(){
delete ui;
}
내가 MainWindow를 슬롯에했다 : 이것은 mainwindow.cpp void MainWindow::deplasare()
인 신호와 상기 슬라이드에 연결하기 위해,하지만,이 기능의 내용을 파악할 수 없다.
감사합니다. 한 가지를 제외하고는 잘 작동합니다. 그 다음 데이터는 이전 값으로 그려져 있습니다. – Ana
그런 다음 새 포인트를 추가 할 때도 트랙을 유지해야합니다. 'offset'을 클래스의 멤버로 유지하고'deplasare'가 호출 될 때마다 새로운 값으로 업데이트하십시오. 그리고 새로운 값을 추가 할 때'value + offset'을 붙이면됩니다. –