示例#1
0
void CurrencyPane::UpdateGraph(const QMap<double, double> map) {
    QCustomPlot* customPlot = ui->plotWidget;

    if (map.size() < 2) {
        customPlot->hide();
        return;
    }
    if (customPlot->isHidden()) {
        customPlot->show();
    }

    //customPlot->setBackground(Qt::transparent);

    double lastDate = map.lastKey();
    double weekAgo = QDateTime(QDate::currentDate()).addDays(-7).toTime_t();

    double highestVal = 0;
    if (!map.isEmpty()) {
        highestVal = from(map.values().toVector().toStdVector()).max();
    }

    if (customPlot->graphCount() > 0) {
        customPlot->removeGraph(0);
    }
    customPlot->addGraph();
    customPlot->graph()->setName("Net Worth");
    QPen pen;
    pen.setColor(QColor(0, 0, 255, 200));
    customPlot->graph()->setLineStyle(QCPGraph::lsLine);
    customPlot->graph()->setPen(pen);
    customPlot->graph()->setBrush(QBrush(QColor(255/4.0,160,50,150)));
    customPlot->graph()->setData(map.keys().toVector(), map.values().toVector());

    // configure bottom axis to show date and time instead of number:
    customPlot->xAxis->setTickLabelType(QCPAxis::ltDateTime);
    customPlot->xAxis->setDateTimeFormat("ddd");
    // set a more compact font size for bottom and left axis tick labels:
    customPlot->xAxis->setTickLabelFont(QFont(QFont().family(), 8));
    customPlot->yAxis->setTickLabelFont(QFont(QFont().family(), 8));
    // set axis labels:
    customPlot->xAxis->setLabel("Date");
    customPlot->yAxis->setLabel("Total Worth in Chaos");
    // make top and right axes visible but without ticks and labels:
    customPlot->xAxis2->setVisible(true);
    customPlot->yAxis2->setVisible(true);
    customPlot->xAxis2->setTicks(false);
    customPlot->yAxis2->setTicks(false);
    customPlot->xAxis2->setTickLabels(false);
    customPlot->yAxis2->setTickLabels(false);
    // set axis ranges to show all data:
    customPlot->xAxis->setRange(weekAgo, lastDate);
    customPlot->yAxis->setRange(0, highestVal);
    // show legend:
    customPlot->legend->setVisible(true);
}
示例#2
0
void Snakes::drawPlot(std::vector<double> inputX, std::vector<double> inputY) {

	QCustomPlot *customPlot = new QCustomPlot();
	customPlot->resize(500, 500);
	
	QVector<double> x = QVector<double>::fromStdVector(inputX);
	QVector<double> y = QVector<double>::fromStdVector(inputY);

	customPlot->addGraph();
	customPlot->graph(0)->setData(x, y);
	customPlot->xAxis->setLabel("x");
	customPlot->yAxis->setLabel("y");
	customPlot->xAxis->setRange(inputX.front(), inputX.back());
	customPlot->yAxis->setRange(inputY.front(), inputY.back());
	customPlot->replot();

	customPlot->show();
}