QCustomPlot Discussion and Comments

arrow at spezial pointReturn to overview

Hi I have studied :Basic example using arrow and text.
I have a QTableList and the according plot.My xaxis is filled with timestamps. Now I have created a z vector which is filled with 1 to rows_count.I have a second xaxis2 with setData ( z , y61 ).
How could i set the arrow in the plot to that spezial point in the QTable List where for example the row is 200,the column is 250 and data at that point is 800?
| column250 |
-------------------------------------------------------------------------------------------------------------------------------------------------------------
row 200 | 800 |
---------------------------------------------------------------------------------------------------------------------------------------------------------
row 201 | |

After some search i wrote this[code]
void MainWindow::cellSelectedSlot3(int row, int column)
{


// add the text label at the top:
QCPItemText *TextLabel = new QCPItemText(m_ui->logplot);
TextLabel->setPositionAlignment(Qt::AlignTop|Qt::AlignHCenter);
TextLabel->position->setType(QCPItemPosition::ptAxisRectRatio);
TextLabel->position->setCoords(0.5, 0); // place position at center/top of axis rect
TextLabel->setText("Punkt aus logfile");
TextLabel->setFont(QFont(font().family(), 16)); // make font a bit larger
TextLabel->setPen(QPen(Qt::black)); // show black border around text

// add the arrow:
QCPItemLine *arrow = new QCPItemLine(m_ui->logplot);
arrow->start->setParentAnchor(TextLabel->bottom);


int Wert= m_ui->logfilewidget->item(row,column)->text().toInt();

qDebug() << "Zeile10372:"<<row;//row=200
qDebug() << "Zeile10372:"<<column;//column=250
qDebug() << "Zeile10373:"<<Wert;//800
z.append(row.toDouble()); // no conversion!
y61.append (Wert.toDouble());// no conversion
m_ui->logplot->graph(61)->setVisible(true);
arrow->end->setCoords (row,Wert); // point to (200,800) in x-y-plot coordinates,Ineed the xaxis1-y-plot
arrow->setHead(QCPLineEnding::esSpikeArrow);
m_ui->logplot->replot();
}
but with the graph i have conversion problems and with the arrow i get a straight line.

I thought I have a new solution. I still have my vektor z which is filled with 1 to line_count.
I have setup graph(61) with xaxis2 and yaxis.
but when i run the programm i get the error:
void QCPITEMTracer::updatePosition() graph has no data
what is wrong?

 m_ui->logplot->addGraph(m_ui->logplot->xAxis2,m_ui->logplot->yAxis);
         m_ui->logplot->graph(61)->setVisible(true);
 QVector<double>(y61).clear();
   m_ui->logplot->graph(61)->setData( z,y61);
              m_ui->logplot->graph(61)->rescaleAxes();
              m_ui->logplot->graph(61)->rescaleValueAxis();

void MainWindow::cellSelectedSlot3(int row, int column)
{

int Wert= m_ui->logfilewidget->item(row,column)->text().toInt();

 qDebug() << "Zeile10372:"<<row;//row=200
  qDebug() << "Zeile10372:"<<column;//column=250
  qDebug() << "Zeile10373:"<<Wert;//800
  z.append(double(row));
  y61.append(double(Wert));
  m_ui->logplot->xAxis2->atBottom;
   m_ui->logplot->xAxis2->setVisible(true);
  m_ui->logplot->graph(61)->setVisible(true);

   QCPItemTracer *phaseTracer = new QCPItemTracer(m_ui->logplot);
   phaseTracer->setGraph( m_ui->logplot->graph(61));
   phaseTracer->setGraphKey(row);
   phaseTracer->visible();
  // phaseTracer->setInterpolating(true);
   phaseTracer->setStyle(QCPItemTracer::tsCircle);
   phaseTracer->setPen(QPen(Qt::red));
   phaseTracer->setBrush(Qt::red);
   phaseTracer->setSize(7);
 qDebug() << "Zeile10766:z"<<z;//200
  qDebug() << "Zeile10767:y61"<<y61;//800

m_ui->logplot->replot();
}

what is the " phaseTracer->setGraphKey(row);" for?

How can I set the position or anchor in my example?

 Public Functions inherited from QCPAbstractItem

QCPAbstractItem (QCustomPlot *parentPlot)
bool clipToAxisRect () const
QCPAxisRect *clipAxisRect () const
bool selectable () const
bool selected () const
void setClipToAxisRect (bool clip)
void setClipAxisRect (QCPAxisRect *rect)
Q_SLOT void setSelectable (bool selectable)
Q_SLOT void setSelected (bool selected)
QList< QCPItemPosition * >positions () const
QList< QCPItemAnchor * >anchors () const
QCPItemPosition * position (const QString &name) const
QCPItemAnchor * anchor (const QString &name) const
bool hasAnchor (const QString &name) const

This version is working but :
xaxis2 is not shown
when i zoom, only xaxis will be zoomed
m_ui->log-plot->raise
m_ui->logplot->replot
m_ui->logplot->show
have no action
when i call this code a second or third time,
both vectors will not be cleared

  
       m_ui->logplot->addGraph(m_ui->logplot->xAxis2,m_ui->logplot->yAxis);
         m_ui->logplot->graph(61)->setVisible(false);
         m_ui->logplot->xAxis2->setVisible(true);
         m_ui->logplot->xAxis2->setRange(0,10);
         m_ui->logplot->xAxis2->setTickLabels(true);
         m_ui->logplot->rescaleAxes();

void MainWindow::cellSelectedSlot3(int row, int column)
{

   int v=line_count;// identisch mit line_count
   m_ui->logplot->xAxis2->setRange(0,v);
   QCPItemTracer *phaseTracer = new QCPItemTracer(m_ui->logplot);
   int Wert= m_ui->logfilewidget->item(row,column)->text().toInt();
  // phaseTracer->setGraphKey(xAxis2);
   QVector<double>(y61).clear();
   QVector<double>(z).clear();
   z.append(double(row));
   y61.append(double(Wert));
   m_ui->logplot->graph(61)->setData( z,y61);
   m_ui->logplot->graph(61)->rescaleAxes();
   m_ui->logplot->graph(61)->rescaleValueAxis();
   phaseTracer->setGraph(m_ui->logplot->graph(61));
   phaseTracer->visible();
   phaseTracer->setStyle(QCPItemTracer::tsCircle);
   phaseTracer->setPen(QPen(Qt::red));
   phaseTracer->setBrush(Qt::red);
   phaseTracer->setSize(10);