// prepare data:
QVector<double> x1(4), y1(4);
for (int i=0; i<x3.size(); ++i)
{
x4[i] = i + 1;
y4[i] = i + 1;
}
QCPBars *bars1 = new QCPBars(customPlot->xAxis, customPlot->yAxis);
bars1->setWidth(9/(double)x4.size());
bars1->setData(x3, y3);
bars1->setPen(QPen(Qt::red));
bars1->setBrush(QColor(10, 140, 70, 160));
效果如下: