本文整理汇总了C++中QCPGraph类的典型用法代码示例。如果您正苦于以下问题:C++ QCPGraph类的具体用法?C++ QCPGraph怎么用?C++ QCPGraph使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QCPGraph类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addBaseLine
void ScatterWidget::addBaseLine(const PointD &p1, const PointD &p2, string legend)
{
QCPGraph *graph = NULL;
int nG = ui->scatter->graphCount();
for(int j=0; j<nG; j++)
{
if(ui->scatter->graph(j)->name() == QString::fromStdString(legend))
{
graph = ui->scatter->graph(j);
break;
}
}
if(!graph)
{
graph = ui->scatter->addGraph();
// ----------------------- Scatter Configuration ---------------------------
graph->setName(QString::fromStdString(legend));
QColor color_ = colorManager.getNewDifferentColor();
graph->setPen(QPen(color_));
}
QVector<double> keys, vals;
keys << p1.x << p2.x;
vals << p1.y << p2.y;
graph->setData(keys, vals);
}
示例2: onPacketParsed
void MainWindow::onPacketParsed(Packet packet)
{
_packetsReceivedCount++;
if(!packet.isCrcValid())
{
_crcErrorCount++;
}
QString sourceId = ByteArrayUtils::toString(packet.sourceId()).replace(" 0x", "").replace("0x", "");
if(!_rssValues.contains(sourceId))
{
_rssValues.insert(sourceId, QVector<double>());
_timestampValues.insert(sourceId, QVector<double>());
QCPGraph* deviceGraph = ui->plotWidget->addGraph();
deviceGraph->setScatterStyle(QCP::ssDisc);
deviceGraph->setScatterSize(5);
deviceGraph->setName(sourceId);
ensureDistinctColors();
}
_rssValues[sourceId].append(packet.rss());
_timestampValues[sourceId].append(packet.timestamp().toTime_t());
updatePlot();
updateStatus();
}
示例3: selectionChanged
void ScatterWidget::selectionChanged()
{
/*
normally, axis base line, axis tick labels and axis labels are selectable separately, but we want
the user only to be able to select the axis as a whole, so we tie the selected states of the tick labels
and the axis base line together. However, the axis label shall be selectable individually.
The selection state of the left and right axes shall be synchronized as well as the state of the
bottom and top axes.
Further, we want to synchronize the selection of the graphs with the selection state of the respective
legend item belonging to that graph. So the user can select a graph by either clicking on the graph itself
or on its legend item.
*/
// make top and bottom axes be selected synchronously, and handle axis and tick labels as one selectable object:
if (ui->scatter->xAxis->selectedParts().testFlag(QCPAxis::spAxis) || ui->scatter->xAxis->selectedParts().testFlag(QCPAxis::spTickLabels) ||
ui->scatter->xAxis2->selectedParts().testFlag(QCPAxis::spAxis) || ui->scatter->xAxis2->selectedParts().testFlag(QCPAxis::spTickLabels))
{
ui->scatter->xAxis2->setSelectedParts(QCPAxis::spAxis|QCPAxis::spTickLabels);
ui->scatter->xAxis->setSelectedParts(QCPAxis::spAxis|QCPAxis::spTickLabels);
}
// make left and right axes be selected synchronously, and handle axis and tick labels as one selectable object:
if (ui->scatter->yAxis->selectedParts().testFlag(QCPAxis::spAxis) || ui->scatter->yAxis->selectedParts().testFlag(QCPAxis::spTickLabels) ||
ui->scatter->yAxis2->selectedParts().testFlag(QCPAxis::spAxis) || ui->scatter->yAxis2->selectedParts().testFlag(QCPAxis::spTickLabels))
{
ui->scatter->yAxis2->setSelectedParts(QCPAxis::spAxis|QCPAxis::spTickLabels);
ui->scatter->yAxis->setSelectedParts(QCPAxis::spAxis|QCPAxis::spTickLabels);
}
// synchronize selection of graphs with selection of corresponding legend items:
for (int i=0; i<ui->scatter->graphCount(); ++i)
{
QCPGraph *graph = ui->scatter->graph(i);
QCPPlottableLegendItem *item = ui->scatter->legend->itemWithPlottable(graph);
if (graph->selected())
{
item->setSelected(true);
//graph->setSelection(QCPDataSelection(graph->data()->dataRange()));
}
else
item->setSelected(false);
}
//synchronize selection of graphs with selection of corresponding legend items:
for (int i=0; i<ui->scatter->lineGraphCount(); ++i)
{
QCPLineBasedGraph *graph = ui->scatter->lineGraph(i);
QCPPlottableLegendItem *item = ui->scatter->legend->itemWithPlottable(graph);
if (graph->selected())
{
item->setSelected(true);
//graph->setSelection(QCPDataSelection(graph->data()->dataRange()));
}
else
item->setSelected(false);
}
}
示例4: createGraph
static void createGraph(QCustomPlot *plot, QVector<double> &steps, QVector<double> &data, const Qt::GlobalColor &color, const Qt::PenStyle &style, const int width)
{
QCPGraph *graph = plot->addGraph();
QPen pen(color);
pen.setStyle(style);
pen.setWidth(width);
graph->setPen(pen);
graph->setData(steps, data);
}
示例5: createWaveFormPic
void Record::createWaveFormPic(Ffmpeg_t *ffmpeg, QString recortPath) {
std::pair<std::vector<double>, std::vector<double> > dataWaveForm = ffmpeg->getSamplesForWaveformPlotting(recortPath + "/" + m_Name);
QCustomPlot Plotter;
Plotter.setBackground(QBrush(Qt::transparent) );
Plotter.xAxis->setVisible(false);
Plotter.yAxis->setVisible(false);
Plotter.axisRect()->setAutoMargins(QCP::msNone);
Plotter.axisRect()->setMargins(QMargins(0, 5, 0, 5));
QCPGraph *Waveform = Plotter.addGraph();
Waveform->setPen(QPen(Qt::green) );
if (!Waveform)
{
qDebug("addGraph failed\n");
}
QVector<double> Amplitudes(QVector<double>::fromStdVector(dataWaveForm.first) );
QVector<double> Time;
double CurrentTime = 0;
auto TimeSlotCount = Amplitudes.size();
for (int64_t i = 1; i < TimeSlotCount; i++)
{
Time.append(CurrentTime);
CurrentTime += 0.5;
}
Waveform->setData(Time, Amplitudes);
Plotter.xAxis->setRange(0, Time.back() );
Plotter.yAxis->setRange(SHRT_MIN, SHRT_MAX);
QByteArray ByteArray;
QBuffer Buffer(&ByteArray);
Buffer.open(QBuffer::WriteOnly);
uint32_t time = m_EndTime - m_StartTime;
for (int i = 1; i < 10000; i*=10) {
Plotter.toPixmap(time/(i), this->height()).save(&Buffer, "PNG", 0);
//Plotter.saveJpg(recortPath + "/plot" + QString::number(m_Id) + QString::number(i) + ".jpg", time/(i), this->height());
QPixmap Pixmap;
Pixmap.loadFromData(ByteArray, "PNG");
v_PixWaves.append(Pixmap);
ByteArray.clear();
Buffer.reset();
}
Buffer.close();
qDebug() << m_WavePic->margin();
// místo 2 podle toho jaký zoom
m_WavePic->setPixmap(v_PixWaves[2]);
}
示例6: QT_VERSION_CHECK
void MainWindow::setupDateTest(QCustomPlot *customPlot)
{
#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0)
customPlot->xAxis->setTickLabelType(QCPAxis::ltDateTime);
QCPGraph *g = customPlot->addGraph();
g->addData(QDateTime(QDate(350,5,21), QTime(0, 0)).toMSecsSinceEpoch()/1000.0, 1);
g->addData(QDateTime(QDate(650,5,21), QTime(0, 0)).toMSecsSinceEpoch()/1000.0, 2);
g->addData(QDateTime(QDate(740,5,21), QTime(0, 0)).toMSecsSinceEpoch()/1000.0, 4);
g->addData(QDateTime(QDate(1000,5,21), QTime(0, 0)).toMSecsSinceEpoch()/1000.0, 8);
g->rescaleAxes();
#endif
}
示例7: createGraph
QCPGraph* SensorDashboard::createGraph(const QString& name, const QColor& color)
{
QPen pen;
pen.setBrush(color);
QCPGraph *graph = mPlot->addGraph();
graph->setName(name);
graph->setLineStyle(QCPGraph::lsLine);
graph->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssNone));
graph->setPen(pen);
return graph;
}
示例8: switch
void DataExplorer::updateDetails() {
//qDebug() << "SELECT!";
ui->runPlot->clearPlottables();
QVector<QString> labels;
QVector<double> ticks;
int colid = 0;
switch (ui->detailType->currentIndex()) {
case 0:
ui->runPlot->xAxis->setAutoTicks(true);
ui->runPlot->xAxis->setAutoTickLabels(true);
for (QCPAbstractPlottable *p : ui->selectEnvironment->selectedPlottables()) {
int unitid = p->property("UID").toInt();
int envid = p->property("EID").toInt();
DataSeries v = exp->runs.keys().at(envid)->run(unitid,ui->runNo->value(),exp);
QCPGraph *g = ui->runPlot->addGraph();
g->setName(v.descriptor->name()+" @ "+exp->runs.keys().at(envid)->label);
g->setProperty("Unit",v.descriptor->unit());
g->setPen(origcols[colid++%origcols.size()]);
g->setData(v.getTimestamps(),v.getValues());
}
break;
case 1:
for (QCPAbstractPlottable *p : ui->selectEnvironment->selectedPlottables()) {
int unitid = p->property("UID").toInt();
int envid = p->property("EID").toInt();
StatisticalSet vals = exp->runs.keys().at(envid)->integral(unitid,exp);
QCPStatisticalBox* b = new QCPStatisticalBox(ui->runPlot->xAxis,ui->runPlot->yAxis);
b->setData(colid,vals.min(),vals.quantile(0.25),vals.median(),vals.quantile(0.75),vals.max());
b->setProperty("StdDev",vals.getStdDev());
b->setProperty("avg",vals.avg());
b->setProperty("avgTime",vals.avgTime());
qWarning() << exp->data.at(unitid)->descriptor->name() << exp->runs.keys().at(envid)->label << vals.avg() << vals.avgTime() << vals.getStdDev();
ui->runPlot->addPlottable(b);
labels.append(QString("%1 @ %2").arg(exp->data.at(unitid)->descriptor->name(),exp->runs.keys().at(envid)->label));
ticks.append(colid++);
ui->runPlot->xAxis->setAutoTicks(false);
ui->runPlot->xAxis->setAutoTickLabels(false);
ui->runPlot->xAxis->setSubTickCount(0);
ui->runPlot->xAxis->setTickLength(0, 4);
ui->runPlot->xAxis->setTickLabelRotation(90);
ui->runPlot->xAxis->setTickVector(ticks);
ui->runPlot->xAxis->setTickVectorLabels(labels);
}
break;
case 2: break;
}
ui->runPlot->rescaleAxes();
if (ui->axisFromZero->isChecked())
ui->runPlot->yAxis->setRangeLower(0);
ui->runPlot->replot();
}
示例9: g_list_last
void SCTPGraphDialog::drawTSNGraph()
{
GList *listTSN = NULL,*tlist;
tsn_t *tsn;
guint8 type;
guint32 tsnumber=0;
if (direction == 1) {
listTSN = g_list_last(selected_assoc->tsn1);
} else {
listTSN = g_list_last(selected_assoc->tsn2);
}
while (listTSN) {
tsn = (tsn_t*) (listTSN->data);
tlist = g_list_first(tsn->tsns);
while (tlist)
{
type = ((struct chunk_header *)tlist->data)->type;
if (type == SCTP_DATA_CHUNK_ID || type == SCTP_I_DATA_CHUNK_ID || type == SCTP_FORWARD_TSN_CHUNK_ID) {
tsnumber = g_ntohl(((struct data_chunk_header *)tlist->data)->tsn);
yt.append(tsnumber);
xt.append(tsn->secs + tsn->usecs/1000000.0);
ft.append(tsn->frame_number);
}
tlist = g_list_next(tlist);
}
listTSN = g_list_previous(listTSN);
}
QCPScatterStyle myScatter;
myScatter.setShape(QCPScatterStyle::ssCircle);
myScatter.setSize(3);
int graphcount = ui->sctpPlot->graphCount();
// create graph and assign data to it:
// Add TSN graph
if (xt.size() > 0) {
QCPGraph *gr = ui->sctpPlot->addGraph();
gr->setName(QString("TSN"));
myScatter.setPen(QPen(Qt::black));
myScatter.setBrush(Qt::black);
ui->sctpPlot->graph(graphcount)->setScatterStyle(myScatter);
ui->sctpPlot->graph(graphcount)->setLineStyle(QCPGraph::lsNone);
ui->sctpPlot->graph(graphcount)->setData(xt, yt);
typeStrings.insert(graphcount, QString(tr("TSN")));
}
}
示例10: pointInfo
void DataExplorer::pointInfo(QMouseEvent *event)
{
QCPAbstractPlottable *plottable = ui->runPlot->plottableAt(event->localPos());
if (!plottable) return;
double x = ui->runPlot->xAxis->pixelToCoord(event->localPos().x());
QToolTip::hideText();
QCPGraph *graph = qobject_cast<QCPGraph*>(plottable);
if (graph) {
double key = 0;
double value = 0;
bool ok = false;
double m = std::numeric_limits<double>::max();
for (QCPData data : graph->data()->values()) {
double d = qAbs(x - data.key);
if(d < m) {
key = data.key;
value = data.value;
ok = true;
m = d;
}
}
if (!ok) return;
QToolTip::showText(event->globalPos(),
tr("<center><b>%L1</b><br/>%L2 %[email protected] %L4s</center>").
arg(graph->name().isEmpty() ? "..." : graph->name()).
arg(value).arg(graph->property("unit").toString()).
arg(key),
ui->runPlot, ui->runPlot->rect());
return;
}
QCPStatisticalBox *graphBox = qobject_cast<QCPStatisticalBox*>(plottable);
if (graphBox) {
QToolTip::showText(event->globalPos(),
tr("<center><b>%L1</b><br/></center>Max: %2<br/>Upper: %3<br/>Median: %4<br/>Lower: %5<br/>Min: %6<br/>StdDev: %7<br/>Avg: %8<br/>Avg Time: %9").
arg(graphBox->name().isEmpty() ? "..." : graphBox->name()).
arg(graphBox->maximum()).arg(graphBox->upperQuartile()).arg(graphBox->median()).
arg(graphBox->lowerQuartile()).arg(graphBox->minimum()).
arg(graphBox->property("StdDev").toDouble()).arg(graphBox->property("avg").toDouble()).
arg(graphBox->property("avgTime").toDouble()),
ui->runPlot, ui->runPlot->rect());
}
}
示例11: setupItemTracerTest_MyTest_addGrap
void MainWindow::setupItemTracerTest_MyTest_addGrap(QCustomPlot *customPlot, QCPAxisRect* pAxisRect)
{
QCPGraph *graph = customPlot->addGraph(pAxisRect->axis(QCPAxis::atBottom), pAxisRect->axis(QCPAxis::atLeft));
int n = 200;
QVector<double> x(n), y(n);
for (int nIndex=0; nIndex<n; ++nIndex)
{
//x[i] = 0.5+i/(double)n*4;
unsigned int nTimeNow = 0;
double xValue = 0.5 + nIndex/(double)n*4;
nTimeNow = QDateTime::currentDateTime().toTime_t() + nIndex;
x[nIndex] = nTimeNow;
//y[nIndex] = qSin(x[nIndex])+1.5;//
y[nIndex] = qSin(xValue)+1.5;//
}
graph->setData(x, y);
}
示例12: ConvertProfile
void ConvertProfile(TProfile* prof, QCPGraph &graph){
//how we put the profile histogram in Qt.
//passing the graph to alter is just easier :)
QVector<double> xvals,yvals,xerrs, yerrs;
int nbins = prof->GetNbinsX();
//get the values
for(int i=0; i<nbins;++i){
xvals.push_back(prof->GetBinCenter(i+1));
yvals.push_back(prof->GetBinContent(i+1));
xerrs.push_back(prof->GetBinWidth(i+1)/2.);
yerrs.push_back(prof->GetBinError(i+1));
}
graph.setData(xvals, yvals);
graph.setDataValueError(xvals, yvals, yerrs);//symmetric errors, only in y.
graph.setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, QPen(Qt::black, 1.5), QBrush(Qt::white), 9));
graph.setPen(QPen(QColor(120, 120, 120), 2));
graph.setLineStyle(QCPGraph::LineStyle::lsNone);
return;
}
示例13: updateChannel
void RealTimePlot::updateChannel(int index)
{
Channel *chan = channels[index];
// Get parameters from channel
QCPGraph *line = chan->getPtrGraphLine();
QCPGraph *marker = chan->getPtrGraphMarker();
QColor color = chan->getGraphColor();
// Set parameters of line graph
line->setPen(QPen(color));
line->setLineStyle(QCPGraph::lsLine);
line->setVisible(chan->getVisible(LINE));
// Set parameters of marker graph
marker->setName(chan->getName());
marker->setPen(QPen(color));
marker->setLineStyle(QCPGraph::lsNone);
marker->setScatterStyle(chan->getMarkerStyle());
marker->setVisible(chan->getVisible(MARKER));
}
示例14: q_data
void ScatterWidget::setData(const std::vector<PointD> &data, string legend)
{
QCPGraph *graph = NULL;
int nG = ui->scatter->graphCount();
for(int i=0; i<nG; i++)
{
if(ui->scatter->graph(i)->name() == QString::fromStdString(legend))
{
graph = ui->scatter->graph(i);
break;
}
}
if(!graph)
{
graph = ui->scatter->addGraph();
// ----------------------- Scatter Configuration ---------------------------
graph->setName(QString::fromStdString(legend));
QColor color_ = colorManager.getNewDifferentColor();
graph->setPen(QPen(color_));
graph->setLineStyle(QCPGraph::lsNone);
graph->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssPlusCircle, 4));
ui->scatter->legend->setVisible(true);
}
double min_x = INFINITY, min_y = INFINITY;
double max_x = -INFINITY, max_y = -INFINITY;
QVector<QCPGraphData> q_data(data.size());
for(unsigned int i=0; i<data.size(); i++)
{
q_data[i] = QCPGraphData(data[i].x, data[i].y);
if(ui->recButton->isChecked())
{
vector<double> vec2_double(2);
vec2_double[0] = data[i].x;
vec2_double[1] = data[i].y;
vector<string> vec2_string(2);
vec2_string[0] = legend + "_x";
vec2_string[1] = legend + "_y";
logger.addLogCsv(graph->dataCount(), vec2_string, vec2_double);
}
max_x = qMax(data[i].x, ui->scatter->xAxis->range().upper);
min_x = qMin(data[i].x, ui->scatter->xAxis->range().lower);
max_y = qMax(data[i].y, ui->scatter->yAxis->range().upper);
min_y = qMin(data[i].y, ui->scatter->yAxis->range().lower);
}
graph->data()->set(q_data);
ui->scatter->xAxis->setRange(min_x, max_x);
ui->scatter->yAxis->setRange(min_y, max_y);
ui->scatter->replot();
}
示例15: QCPGraph
void MainWindow::on_listView_clicked(const QModelIndex &index)
{
//QModelIndex a = ui->listView->selectedIndexes().back();
QVariant selected = dataModel->compNameList->data(index,Qt::DisplayRole);
dataModel->dataViewComp = selected.toString();
QVector<double> dataViewPrice = dataModel->priceBuff.value(selected.toString());
QVector<double> xval;
QVector<double> baseVal;
if(dataViewPrice.empty()) return;
double min = dataViewPrice[0];
for(auto &i : dataViewPrice) min = std::fmin(min,i);
for(int i = 0; i<dataViewPrice.size(); i++){
xval<<i;
baseVal<<min;
}
QCustomPlot* p = ui->qcpDataView;;
p->clearGraphs();
QCPGraph* timeline = new QCPGraph(p->xAxis,p->yAxis);
timeline->addData(xval,dataViewPrice);
QCPGraph* base = new QCPGraph(p->xAxis,p->yAxis);
base->setData(xval,baseVal);
p->addPlottable(timeline);
p->addPlottable(base);
timeline->setChannelFillGraph(base);
timeline->setPen(QPen(QColor(0,0,0,0)));
timeline->setBrush(QColor(0,0,255,100));
//QVector<double> ticks;
QVector<QString> labels;
int L = this->dataModel->dateBuff.values()[0].size()-1;
int len = 6;
float step = (float)L/(float)len;
for(int i = 0; i<= len; i++){
labels<<this->dataModel->dateBuff.values()[0][i*step].toString("MM/yy");
}
p->xAxis->setTickVectorLabels(labels);
p->xAxis->setAutoTicks(true);
p->xAxis->setAutoTickLabels(false);
p->xAxis->setTickLabelRotation(-60);
//p->xAxis->setSubTickCount(0);
//p->xAxis->setTickLength(0, len-1);
p->xAxis->grid()->setVisible(true);
//p->xAxis->setRange(0, len-2);
//p->xAxis->setTickVector(ticks);
p->rescaleAxes();
p->replot();
}