lundi 21 août 2023

QTCharts building charts with time

I have QVector<QTime> time, with "hh:mm:ss.zzz" format, how can i build a normal QtCharts with this format on X. On Y i will use QVector<double>.

I try to use append in QLineSeries, but nothing work

I try to build to graphs with equals data

    QVector<double> test(30);
    for (int i = 0; i < test.size(); ++i)
    {
        test.push_back(0.03);
    }
    
    
    QChartView* chartView = nullptr;
    QLineSeries* series = nullptr;
    QChart* chart = nullptr;
    QDateTimeAxis* axisX = nullptr;
    QDateTimeAxis* axisY = nullptr;
    
    for (size_t i = 0; i < 2; ++i)
    {
        chartView = new QChartView(this);

        ui->graphPrint->addWidget(chartView);

        series = new QLineSeries;
        
        for (int j = 0; j < time.size(); ++j)
        {
            QString formattedTime = time[i].toString("hh:mm:ss.zzz");
            series->append(formattedTime, test[i]);
        }
        
        chart = new QChart();
        
        
        axisX = new QDateTimeAxis();
        axisX->setFormat("hh:mm:ss.zzz");
        chart->addAxis(axisX, Qt::AlignBottom);
        
    }
    
    delete chartView;
    delete series;
    delete axisX;
    delete axisY;

Aucun commentaire:

Enregistrer un commentaire