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. Why Does QtCustomPlot show weekend dates when passing in JSON

Why Does QtCustomPlot show weekend dates when passing in JSON

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 93 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.
  • L Offline
    L Offline
    Laner107
    wrote on last edited by
    #1

    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++)
        {
                value.push_back(chartData[i]["close"].asDouble());
                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);
        ui->stockGraph->replot();
    

    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.

    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