Qt World Summit: Register Today!

Why Does QtCustomPlot show weekend dates when passing in JSON

  • I am creating a program to chart stock movement and I I get a json format that looks like this:

    [{"date":"2020-05-19","open":329.35,"close":327.68,"high":330.11,"low":321.54,"volume":25817665,"uOpen":315.12,"uClose":320.4,"uHigh":325.67,"uLow":326.75,"uVolume":26261800,"change":0,"changePercent":0,"label":"May 19","changeOverTime":0}

    I basically pull from the "date" variable and transform it to secsSinceEpoch like this:

    //Reads in data from json(historical data 1 day delayed)
        for(Json::Value::ArrayIndex i = 0 ; i < 5; i++)
                time[i] = chartData[i]["date"].asString();
                timeInEpoch.push_back(QDateTime::fromString(time[i].c_str(), Qt::ISODate).toSecsSinceEpoch());
                cout << timeInEpoch[i] << endl;
                if((value[i] == 0) && (i != chartData.size() - 1))
                    value[i] = value[i-1];
                if(value[i] > maxAvg)
                    maxAvg = value[i];
                else if(value[i] < minAvg)
                    minAvg = value[i];
        stockData(value[n-1], value[n-2]);
        //Assigns data to graph
        ui->stockGraph->graph(0)->setData(timeInEpoch, value);
        //Set x axis range
        ui->stockGraph->xAxis->setRange(timeInEpoch[0], timeInEpoch[4]);
        //Set y axis range
        ui->stockGraph->yAxis2->setRange(minAvg - 10, maxAvg + 10);

    But my output still shows weekends which should never happen as the json format always skips weekends and only shows week days, here is the output

    Any ideas how to do this and is there a better way to represents date on an axis using QCPAxisTickerDateTime? I am kind of confused with it.

Log in to reply