No Description

xyplotwindow.cpp 910B

12345678910111213141516171819202122232425262728293031323334353637
  1. #include "xyplotwindow.h"
  2. #include "ui_xyplotwindow.h"
  3. #include "qcustomplot.h"
  4. #include <cmath>
  5. XYPlotWindow::XYPlotWindow(QWidget *parent) :
  6. QMainWindow(parent),
  7. ui(new Ui::XYPlotWindow)
  8. {
  9. ui->setupUi(this);
  10. }
  11. // Añade la x y y a sus respectivos vectores.
  12. void XYPlotWindow::AddPointToGraph(double x, double y) {
  13. XX.push_back(x);
  14. YY.push_back(y);
  15. }
  16. // Esta función invoca los métodos apropiados de customPlot para que
  17. // se grafiquen los puntos.
  18. void XYPlotWindow::Plot() {
  19. ui->customPlot->xAxis->setLabel("x");
  20. ui->customPlot->yAxis->setLabel("y");
  21. ui->customPlot->xAxis->setRange(-25.0, 25.0);
  22. ui->customPlot->yAxis->setRange(-25.0, 25.0);
  23. QCPCurve *myCurve = new QCPCurve(ui->customPlot->xAxis, ui->customPlot->yAxis);
  24. ui->customPlot->addPlottable(myCurve);
  25. myCurve->setData(XX,YY);
  26. }
  27. XYPlotWindow::~XYPlotWindow()
  28. {
  29. delete ui;
  30. }