Qwt 6.1 legend duplication
-
my code:
@
void MainWindow::drawGraphCpuGeneralSlot(int cpu)
{
int graphTimeInt = ui->spinBox->value();
double graphTimeDouble = (double) graphTimeInt;QwtLegend *legend = new QwtLegend(); ui->graphCPU->setTitle(QString::fromUtf8("cpu")); ui->graphCPU->insertLegend(legend); ui->graphCPU->setFooter("seconds"); ui->graphCPU->setAxisScale(QwtPlot::xBottom,0.0,graphTimeDouble); ui->graphCPU->setAxisTitle(QwtPlot::yLeft,QString::fromUtf8("%")); ui->graphCPU->setAxisScale(QwtPlot::yLeft,0.0,100.0); cpuLine = new QwtPlotCurve(QString("")); cpuLine->setPen(QPen(Qt::darkGreen, mainLineInGraph)); cpuLine->setTitle("usage - " + QString::number(cpu)); this->cpuArray[0] = cpu; cpuLine->setRawSamples(this->cpuArrayTime,this->cpuArray,myIterator); cpuLine->attach(ui->graphCPU); for(int i=myIterator;i!=0;i--) { this->cpuArray[i] = this->cpuArray[i-1]; }
}
@it is slot funtion. Slot is working, but legend is duplicating:
http://farm8.staticflickr.com/7380/11495605866_817e00069c.jpgwhat's my be wrong? Thank you.
-
[quote author="uwer" date="1387730153"]Guess the legend is o.k. but you are creating/attaching another curve with the same title by accident with each data update.[/quote]
Yes, I divided this function to two functions: one for initializing and one for updating. Now it works file. Thank you :)