void ChartPage::setupChart() { this->buildingChart=true; QCustomPlot *customPlot = ui->chartBlock; customPlot->setInteraction(QCP::iRangeDrag, true); customPlot->setInteraction(QCP::iSelectPlottables, true); customPlot->setInteraction(QCP::iSelectItems, true); customPlot->setInteraction(QCP::iRangeZoom, true); customPlot->legend->setVisible(true); customPlot->legend->setFont(QFont("Helvetica",9)); // set locale to english, so we get english decimal separator: customPlot->setLocale(QLocale(QLocale::English, QLocale::UnitedKingdom)); // create graph and assign data to it: customPlot->addGraph(); customPlot->graph(0)->setName("Difficulty"); // customPlot->graph(0)->setData(x, y); // give the axes some labels: customPlot->xAxis->setLabel("Date"); customPlot->yAxis->setLabel("Difficulty"); customPlot->legend->setSelectableParts(QCPLegend::spItems); customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectAxes | QCP::iSelectLegend | QCP::iSelectPlottables); customPlot->axisRect()->setupFullAxesBox(); customPlot->xAxis->setTickLabelType(QCPAxis::ltDateTime); customPlot->xAxis->setDateTimeFormat("dd/MM/yyyy"); customPlot->xAxis->setAutoTickCount(5); //customPlot->yAxis->setAutoTickCount(5); // set axes ranges, so we see all data: customPlot->yAxis->setRange(-0.1, 3); ClientModel *model = this->clientModel; // generate some data: QVector<double> x(1000), y(1000); //, y1(50000); int maxBlocks; maxBlocks = model->getNumBlocks(); if (maxBlocks > 1000) { maxBlocks=1000; } int i = 0; if (maxBlocks > 0) { for (i = 0; i < maxBlocks; i++) { CBlock blk = model->getBlock(i); CBlockIndex* cIndex = model->getBlockIndex(i); x[i]=blk.GetBlockTime(); y[i]=model->getDiff(cIndex); } customPlot->graph(0)->setData(x, y); customPlot->xAxis->setRange(x[i-1]-(60*60*24), x[i-1]); this->lastBlockHeight = i; } customPlot->replot(); this->buildingChart=false; }