QCustomPlot Discussion and Comments

Cannot view x-axis labels or number ticks.Return to overview

I am making a basic bar graph and have looked through all of the sample code found within this site however no matter what I try my graph will not display the x-axis label or tick labels. Here is my code for my x-axis.

    QVector<double> ticks;
    QVector<QString> labels;
    // Switch to an array
    ticks << 1 << 2 << 3 << 4 << 5 << 6 << 7 << 8 << 9 << 10 << 11 << 12 << 13 << 14 << 15 << 16 << 17;
    ticks << 18 << 19 << 20 << 21 << 22 << 23 << 24 << 25 << 26 << 27 << 28 << 29 << 30 << 31 << 32 << 33;
    ticks << 34 << 35 << 36 << 37;
    labels << "v1" << "v2" << "v3" << "v4" << "v5" << "v6" << "v7" << "v8" << "v9" << "v10" << "v11" << "v12" << "v13" << "v14" << "v15" << "v16" << "v17";
    labels << "v18" << "v19" << "v20" << "v21" << "v22" << "v23" << "v24" << "v25" << "v26" << "v27" << "v28" << "v29" << "v30" << "v31" << "v32" << "v33";
    labels << "v34" << "v35" << "v36" << "v37";
    QSharedPointer<QCPAxisTickerText> textTicker(new QCPAxisTickerText);
    textTicker->addTicks(ticks, labels);
    ui->customPlot->xAxis->setTicker(textTicker);
    ui->customPlot->xAxis->setTickLabelRotation(60);
    ui->customPlot->xAxis->setLabel("Values");
    ui->customPlot->xAxis->setSubTicks(false);
    ui->customPlot->xAxis->setTickLength(0, 4);
    ui->customPlot->xAxis->setRange(0, 39);
    ui->customPlot->xAxis->setBasePen(QPen(Qt::white));
    ui->customPlot->xAxis->setTickPen(QPen(Qt::white));
    ui->customPlot->xAxis->setSubTickPen(QPen(Qt::white));
    ui->customPlot->xAxis->grid()->setPen(QPen(QColor(130, 130, 130), 0, Qt::DotLine));
    ui->customPlot->xAxis->setTickLabelColor(Qt::white);
    ui->customPlot->xAxis->setLabelColor(Qt::white);
    ui->customPlot->xAxis->setTickLabels(true);
    ui->customPlot->xAxis->grid()->setVisible(true);
    ui->customPlot->xAxis->grid()->setSubGridVisible(true);

Let it be known that my y-axis is viewable. Any ideas?

I ran into this before. it's not your code it's the size of your widget in qt. Rather than making it larger, try making it smaller. The x-axis will slowly appear.