QDateTimeAxis - multiple series?



  • Hi, I'm wondering if it is possible to display multiple series with QDateTimeAxis. Example: Three series for 2016 with different dates and values (all within 2016).
    Tried to attach axis to series, but only the first one is displayed.
    Let me know if my question is not clear....


  • Moderators

    @qtyeti said:

    Tried to attach axis to series, but only the first one is displayed.

    without code we can just guess whats going wrong in there



  • Code looks like this (adapted from examples):
    QLineSeries *series = new QLineSeries;

    QDateTime xValue;
    xValue.setDate(QDate(2012, 1, 18));
    xValue.setTime(QTime(0, 00));
    qreal yValue = 12;
    series->append(xValue.toMSecsSinceEpoch(), yValue);
    
    xValue.setDate(QDate(2013, 5, 11));
    xValue.setTime(QTime(0, 00));
    yValue = 22;
    series->append(xValue.toMSecsSinceEpoch(), yValue);
    
    xValue.setDate(QDate(2013, 6, 11));
    xValue.setTime(QTime(0, 00));
    yValue = 20;
    series->append(xValue.toMSecsSinceEpoch(), yValue);
    
    QLineSeries *series2 = new QLineSeries;
    
    xValue.setDate(QDate(2012, 2, 18));
    xValue.setTime(QTime(0, 00));
    yValue = 22;
    series2->append(xValue.toMSecsSinceEpoch(), yValue);
    
    xValue.setDate(QDate(2013, 6, 11));
    xValue.setTime(QTime(0, 00));
    yValue = 32;
    series2->append(xValue.toMSecsSinceEpoch(), yValue);
    
    xValue.setDate(QDate(2013, 7, 11));
    xValue.setTime(QTime(0, 00));
    yValue = 30;
    series2->append(xValue.toMSecsSinceEpoch(), yValue);
    
    QChart *chart = new QChart;
    chart->addSeries(series2);
    chart->addSeries(series);
    
    chart->legend()->hide();
    chart->setTitle("Test QDateTimeAxis)");
    
    QDateTimeAxis *axisX = new QDateTimeAxis;
    axisX->setFormat("dd-MM-yyyy h:mm");
    axisX->setTickCount(1);
    axisX->setTitleText("Date");
    chart->addAxis(axisX, Qt::AlignBottom);
    
    series2->attachAxis(axisX);
    series->attachAxis(axisX);
    QValueAxis *axisY = new QValueAxis;
    axisY->setLabelFormat("%i");
    axisY->setTitleText("Test Axis");
    chart->addAxis(axisY, Qt::AlignLeft);
    series2->attachAxis(axisY);
    series->attachAxis(axisY);
    
    Test2Qt w;
    
    QChartView *chartView = new QChartView(chart);
    chartView->setRenderHint(QPainter::Antialiasing);
    w.setCentralWidget(chartView);
    w.resize(820, 600);
    w.show();

  • Moderators

    @qtyeti
    what do the attachAxis() calls return?
    Any warnings in the console?



  • attachAxis both return "TRUE"...
    No warnings in the console.
    Maybe it's not possible to do that at all?



  • Problem fixed - was an issue with the min/max of the value axis.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.