Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Labels do not appear in QChartView
Qt 6.11 is out! See what's new in the release blog

Labels do not appear in QChartView

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 396 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Samuel Ives
    wrote on last edited by
    #1

    I'm trying to generate a sales report that shows the amount of sales of the day on a particular day of the month in the chart.

    RelatorioDeVendas::RelatorioDeVendas(QWidget *parent) :
        QDialog(parent),
        ui(new Ui::RelatorioDeVendas)
    {
        ui->setupUi(this);
    
        QChart *chartMensal = new QChart();
        QLineSeries *seriesMensal = new QLineSeries();
    
        Relatorios::vendasMensais(seriesMensal, chartMensal);
    
        chartMensal->addSeries(seriesMensal);
        chartMensal->setTitle("Vendas do mês");
        chartMensal->legend()->setVisible(false);
    
        ui->chartViewMensal->setRenderHint(QPainter::Antialiasing);
        ui->chartViewMensal->setChart(chartMensal);
    
    }
    
    void Relatorios::vendasMensais(QLineSeries *series, QChart *chart)
    {
    
       QSqlDatabase db = Database::database();
    
       QSqlQuery q(db);
       q.prepare("SELECT COUNT(id), feita_em FROM vendas WHERE YEAR(feita_em) = :ano AND MONTH(feita_em) = :mes GROUP BY DAY(feita_em)");
       q.bindValue(":ano", QDate::currentDate().year());
       q.bindValue(":mes", QDate::currentDate().month());
    
       if(!q.exec()){
           qCritical() << "Falha ao realizar a consulta: " << q.lastError().text();
           return;
       }
    
       QCategoryAxis *xAxis = new QCategoryAxis();
    
       while(q.next()){
    
           QDateTime data = QDateTime::fromString(q.value(1).toString(), "yyyy-MM-ddThh:mm:ss.z");
    
           xAxis->append(QString::number(data.date().day()), data.date().day());
           series->append(data.date().day(), q.value(0).toInt());
    
       }
    
       chart->createDefaultAxes();
       chart->addAxis(xAxis, Qt::AlignBottom);
    
    }
    

    But the days do not appear in the graph even using QCategoryAxis

    ![no labels in chart](0_1560887008630_8b854fc0-c71c-42e1-8fcf-5cfbc976be17-image.png image url)

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved