QCustomPlot Discussion and Comments

replot with pushbuttonReturn to overview

hello custom people !

my problem today is simple :
i want replot but i don't replot !


void MainWindow::on_graphique_clicked()
{
int max;

if(ui->lcdchoix1->value() < ui->lcdchoix2->value())
{
max=ui->lcdchoix2->value();
}
else
{
max=ui->lcdchoix1->value();
}
if(ui->lcdchoix1->value() == ui->lcdchoix2->value())
max=ui->lcdchoix1->value();

customPlot->clearGraphs();
customPlot->clearItems();
customPlot->clearPlottables();


customPlot->setGeometry(50,200,500,500);
// set dark background gradient:
QLinearGradient gradient(0, 0, 0, 400);
gradient.setColorAt(0, QColor(90, 90, 90));
gradient.setColorAt(0.38, QColor(105, 105, 105));
gradient.setColorAt(1, QColor(70, 70, 70));
customPlot->setBackground(QBrush(gradient));

// create empty bar chart objects:
QCPBars *choix1 = new QCPBars(customPlot->xAxis, customPlot->yAxis);
QCPBars *choix2 = new QCPBars(customPlot->xAxis, customPlot->yAxis);

choix1->setAntialiased(false); // gives more crisp, pixel aligned bar borders
choix2->setAntialiased(false);

choix1->setStackingGap(1);
choix2->setStackingGap(1);

// set names and colors:

choix2->setName("Choix 1");
choix2->setPen(QPen(QColor(250, 170, 20).lighter(150)));
choix2->setBrush(QColor(250, 170, 20));
choix1->setName("Choix 2");
choix1->setPen(QPen(QColor(0, 168, 140).lighter(130)));
choix1->setBrush(QColor(0, 168, 140));
// stack bars on top of each other:

//choix1->moveAbove(choix2);

// prepare x axis with country labels:
QVector<double> ticks;
QVector<QString> labels;
ticks << 1 << 2 ;
labels << "choix 1" << "choix 2";
QSharedPointer<QCPAxisTickerText> textTicker(new QCPAxisTickerText);
textTicker->addTicks(ticks, labels);
customPlot->xAxis->setTicker(textTicker);
customPlot->xAxis->setTickLabelRotation(60);
customPlot->xAxis->setSubTicks(false);
customPlot->xAxis->setTickLength(0, 4);
customPlot->xAxis->setRange(0, 3.1);
customPlot->xAxis->setBasePen(QPen(Qt::white));
customPlot->xAxis->setTickPen(QPen(Qt::white));
customPlot->xAxis->grid()->setVisible(true);
customPlot->xAxis->grid()->setPen(QPen(QColor(130, 130, 130), 0, Qt::DotLine));
customPlot->xAxis->setTickLabelColor(Qt::white);
customPlot->xAxis->setLabelColor(Qt::white);

// prepare y axis:
customPlot->yAxis->setRange(0, max+1);
customPlot->yAxis->setPadding(5); // a bit more space to the left border
customPlot->yAxis->setLabel("Nombre de votes");
customPlot->yAxis->setBasePen(QPen(Qt::white));
customPlot->yAxis->setTickPen(QPen(Qt::white));
customPlot->yAxis->setSubTickPen(QPen(Qt::white));
customPlot->yAxis->grid()->setSubGridVisible(true);
customPlot->yAxis->setTickLabelColor(Qt::white);
customPlot->yAxis->setLabelColor(Qt::white);
customPlot->yAxis->grid()->setPen(QPen(QColor(130, 130, 130), 0, Qt::SolidLine));
customPlot->yAxis->grid()->setSubGridPen(QPen(QColor(130, 130, 130), 0, Qt::DotLine));

// Add data:

choix1Data.append(ui->lcdchoix1->value());
choix2Data.append(ui->lcdchoix2->value());

QVector<double> test;
test << 2;


choix1->setData(ticks, choix1Data);
choix2->setData(test, choix2Data);

// setup legend:
customPlot->legend->setVisible(true);
customPlot->axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignTop|Qt::AlignHCenter);
customPlot->legend->setBrush(QColor(255, 255, 255, 100));
customPlot->legend->setBorderPen(Qt::NoPen);
QFont legendFont = font();
legendFont.setPointSize(10);
customPlot->legend->setFont(legendFont);
customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);

customPlot->show();

}


the debug console show :
void QCPBars::addData(const QVector<double>&, const QVector<double>&, bool) keys and values have different sizes: 2 1
void QCPBars::addData(const QVector<double>&, const QVector<double>&, bool) keys and values have different sizes: 1 2

the first plot is good and when i try a second plot the graph not change !

i try with customPlot->replot() but not change.

have you an explain ?

SOLVED excuse me for the post jaja