Advertisement
Guest User

Untitled

a guest
Sep 21st, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. void MainWindow::drawChart(QtCharts::QChart *chart, QtCharts::QXYSeries *series, const QModelIndex &index)
  2. {
  3.     QPointF p;
  4.     QVector<QPointF> points;
  5.  
  6.     double min_x = std::numeric_limits<double>::max();
  7.     double max_x = -std::numeric_limits<double>::max();
  8.  
  9.     double min_y = std::numeric_limits<double>::max();
  10.     double max_y = -std::numeric_limits<double>::max();
  11.  
  12.     QList<QVariant> var = index.data(Qt::DisplayRole).toList();
  13.     for (int i = 0; i < var.size(); i++)
  14.     {
  15.         p = var.at(i).toPointF();
  16.         points << p;
  17.  
  18.         min_x = std::min(min_x, p.x());
  19.         min_y = std::min(min_y, p.y());
  20.  
  21.         max_x = std::max(max_x, p.x());
  22.         max_y = std::max(max_y, p.y());
  23.     }
  24.  
  25.     series->replace(points);
  26.  
  27.     chart->axisX()->setRange(min_x, max_x);
  28.     chart->axisY()->setRange(min_y, max_y);
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement