void MainWindow::setupLayoutElementBugTest(QCustomPlot *customPlot) { QCPLayoutGrid *topLayout = qobject_cast<QCPLayoutGrid*>(customPlot->plotLayout()); QCPAxisRect *r = new QCPAxisRect(customPlot); r->addAxes(QCPAxis::atLeft); topLayout->addElement(0, 0, r); }
void Reportes::inicializarGraficoDesplazamientosRecorridoCurvo() { graficoDesplazamientosRecorridoCurvo->plotLayout()->clear(); graficoDesplazamientosRecorridoCurvo->clearItems(); graficoDesplazamientosRecorridoCurvo->clearGraphs(); //Elementos del grafico QCPAxisRect *topAxisRect = new QCPAxisRect(graficoDesplazamientosRecorridoCurvo); QCPAxisRect *bottomAxisRect = new QCPAxisRect(graficoDesplazamientosRecorridoCurvo); bottomAxisRect->axis(QCPAxis::atLeft)->setRange(0,2); bottomAxisRect->axis(QCPAxis::atBottom)->setRange(0,2); QCPPlotTitle *tituloX=new QCPPlotTitle(graficoDesplazamientosRecorridoCurvo,"Grafico Desplazamiento (Recorrido Curvo) Medio-Lateral vs Tiempo"); QCPPlotTitle *tituloY=new QCPPlotTitle(graficoDesplazamientosRecorridoCurvo,"Grafico Desplazamiento (Recorrido Curvo) Antero-Posterior vs Tiempo"); //Se posicionan los layouts graficoDesplazamientosRecorridoCurvo->plotLayout()->addElement(0, 0, tituloX); graficoDesplazamientosRecorridoCurvo->plotLayout()->addElement(1, 0, topAxisRect); graficoDesplazamientosRecorridoCurvo->plotLayout()->addElement(2, 0, tituloY); graficoDesplazamientosRecorridoCurvo->plotLayout()->addElement(3, 0, bottomAxisRect); //create and configure plottables: graficoDesplazamientoReCurX = graficoDesplazamientosRecorridoCurvo->addGraph(topAxisRect->axis(QCPAxis::atBottom), topAxisRect->axis(QCPAxis::atLeft)); graficoDesplazamientoReCurY = graficoDesplazamientosRecorridoCurvo->addGraph(bottomAxisRect->axis(QCPAxis::atBottom), bottomAxisRect->axis(QCPAxis::atLeft)); //agregarQCPItemLine(lineaIzqDesplazamientoX,graficoDesplazamientos,topAxisRect); lineaIzqDesplazamientoReCurX=new QCPItemLine(graficoDesplazamientosRecorridoCurvo); agregarQCPItemLine(lineaIzqDesplazamientoReCurX,graficoDesplazamientosRecorridoCurvo,topAxisRect); lineaDerDesplazamientoReCurX=new QCPItemLine(graficoDesplazamientosRecorridoCurvo); agregarQCPItemLine(lineaDerDesplazamientoReCurX,graficoDesplazamientosRecorridoCurvo,topAxisRect); lineaIzqDesplazamientoReCurY=new QCPItemLine(graficoDesplazamientosRecorridoCurvo); agregarQCPItemLine(lineaIzqDesplazamientoReCurY,graficoDesplazamientosRecorridoCurvo,bottomAxisRect); lineaDerDesplazamientoReCurY=new QCPItemLine(graficoDesplazamientosRecorridoCurvo); agregarQCPItemLine(lineaDerDesplazamientoReCurY,graficoDesplazamientosRecorridoCurvo,bottomAxisRect); //Colores de la Line graficoDesplazamientoReCurX->setPen(QPen(QColor(71, 71, 194), 2)); graficoDesplazamientoReCurY->setPen(QPen(QColor(153, 102, 51), 2)); //Labels de los ejes topAxisRect->axis(QCPAxis::atLeft)->setLabel("Desplazamiento (centimetros)"); topAxisRect->axis(QCPAxis::atBottom)->setLabel("Tiempo (segundos)"); bottomAxisRect->axis(QCPAxis::atLeft)->setLabel("Desplazamiento (centimetros)"); bottomAxisRect->axis(QCPAxis::atBottom)->setLabel("Tiempo (segundos)"); //Se rescalan los ejes para el autoajuste graficoDesplazamientoReCurX->rescaleAxes(); graficoDesplazamientoReCurY->rescaleAxes(); graficoDesplazamientosRecorridoCurvo->setInteractions(QCP::iRangeDrag|QCP::iRangeZoom); }
void MainWindow::setupInsetLayoutTest(QCustomPlot *customPlot) { customPlot->addLayer("insetLayer"); customPlot->setCurrentLayer("insetLayer"); QCPAxisRect *insetAxRect = new QCPAxisRect(customPlot); insetAxRect->setMinimumSize(300, 250); customPlot->axisRect(0)->insetLayout()->addElement(insetAxRect, Qt::AlignRight|Qt::AlignTop); insetAxRect->setupFullAxesBox(true); insetAxRect->setBackground(QBrush(QColor(240, 240, 240))); }
void MainWindow::setupMultiAxisRectInteractionsMouseMove(QMouseEvent *event) { QCPAxisRect *ar = qobject_cast<QCPAxisRect*>(mCustomPlot->layoutElementAt(event->pos())); if (ar) ar->setBackground(QColor(230, 230, 230)); for (int i=0; i<mCustomPlot->axisRectCount(); ++i) { if (mCustomPlot->axisRect(i) != ar) mCustomPlot->axisRect(i)->setBackground(Qt::NoBrush); } mCustomPlot->replot(); }
void MainWindow::setupMarginGroupTest(QCustomPlot *customPlot) { QCPLayoutGrid *topLayout =customPlot->plotLayout(); QCPAxisRect *r = new QCPAxisRect(customPlot); topLayout->addElement(1, 0, r); r->addAxes(QCPAxis::atLeft|QCPAxis::atRight|QCPAxis::atBottom|QCPAxis::atTop); r->addAxes(QCPAxis::atLeft|QCPAxis::atRight|QCPAxis::atBottom|QCPAxis::atTop); QCPMarginGroup *group = new QCPMarginGroup(customPlot); topLayout->element(0, 0)->setMarginGroup(QCP::msAll, group); topLayout->element(1, 0)->setMarginGroup(QCP::msAll, group); }
void MainWindow::setupMultiAxisRectInteractions(QCustomPlot *customPlot) { QCPAxisRect *r1 = new QCPAxisRect(customPlot); customPlot->plotLayout()->addElement(1, 0, r1); QCPAxisRect *r2 = new QCPAxisRect(customPlot); customPlot->plotLayout()->addElement(0, 1, r2); QCPAxisRect *r3 = new QCPAxisRect(customPlot); customPlot->plotLayout()->addElement(1, 1, r3); QCPAxisRect *inset = new QCPAxisRect(customPlot); inset->setMinimumSize(170, 120); inset->setupFullAxesBox(true); foreach (QCPAxis *ax, inset->axes()) ax->setAutoTickCount(3); r3->insetLayout()->addElement(inset, Qt::AlignRight|Qt::AlignTop); connect(mCustomPlot, SIGNAL(mouseMove(QMouseEvent*)), this, SLOT(setupMultiAxisRectInteractionsMouseMove(QMouseEvent*))); }
void MainWindow::genLayoutsystem_MultipleAxisRects() { resetPlot(false); customPlot->plotLayout()->clear(); // let's start from scratch and remove the default axis rect // add the first axis rect in second row (row index 1): QCPAxisRect *topAxisRect = new QCPAxisRect(customPlot); customPlot->plotLayout()->addElement(1, 0, topAxisRect); // create a sub layout that we'll place in first row: QCPLayoutGrid *subLayout = new QCPLayoutGrid; customPlot->plotLayout()->addElement(0, 0, subLayout); // add two axis rects in the sub layout next to each other: QCPAxisRect *leftAxisRect = new QCPAxisRect(customPlot); QCPAxisRect *rightAxisRect = new QCPAxisRect(customPlot); subLayout->addElement(0, 0, leftAxisRect); subLayout->addElement(0, 1, rightAxisRect); subLayout->setColumnStretchFactor(0, 3); // left axis rect shall have 60% of width subLayout->setColumnStretchFactor(1, 2); // right one only 40% (3:2 = 60:40) // since we've created the axis rects and axes from scratch, we need to place them on // according layers, if we don't want the grid to be drawn above the axes etc. // place the axis on "axes" layer and grids on the "grid" layer, which is below "axes": QList<QCPAxis*> allAxes; allAxes << topAxisRect->axes() << leftAxisRect->axes() << rightAxisRect->axes(); foreach (QCPAxis *axis, allAxes) { axis->setLayer("axes"); axis->grid()->setLayer("grid"); }
DrawFinancialChart::DrawFinancialChart(QWidget *parent) : QCustomPlot(parent) { resize(600,400); legend->setVisible(true); // generate two sets of random walk data (one for candlestick and one for ohlc chart): int n = 500; QVector<double> time(n), value1(n), value2(n); QDateTime start = QDateTime(QDate(2014, 6, 11)); start.setTimeSpec(Qt::UTC); double startTime = start.toTime_t(); double binSize = 3600*24; // bin data in 1 day intervals time[0] = startTime; value1[0] = 60; value2[0] = 20; qsrand(9); for (int i=1; i<n; ++i) { time[i] = startTime + 3600*i; value1[i] = value1[i-1] + (qrand()/(double)RAND_MAX-0.5)*10; value2[i] = value2[i-1] + (qrand()/(double)RAND_MAX-0.5)*3; } // create candlestick chart: QCPFinancial *candlesticks = new QCPFinancial(xAxis, yAxis); addPlottable(candlesticks); QCPFinancialDataMap data1 = QCPFinancial::timeSeriesToOhlc(time, value1, binSize, startTime); candlesticks->setName("Candlestick"); candlesticks->setChartStyle(QCPFinancial::csCandlestick); candlesticks->setData(&data1, true); candlesticks->setWidth(binSize*0.9); candlesticks->setTwoColored(true); candlesticks->setBrushPositive(QColor(245, 245, 245)); candlesticks->setBrushNegative(QColor(0, 0, 0)); candlesticks->setPenPositive(QPen(QColor(0, 0, 0))); candlesticks->setPenNegative(QPen(QColor(0, 0, 0))); // create ohlc chart: QCPFinancial *ohlc = new QCPFinancial(xAxis, yAxis); addPlottable(ohlc); QCPFinancialDataMap data2 = QCPFinancial::timeSeriesToOhlc(time, value2, binSize/3.0, startTime); // divide binSize by 3 just to make the ohlc bars a bit denser ohlc->setName("OHLC"); ohlc->setChartStyle(QCPFinancial::csOhlc); ohlc->setData(&data2, true); ohlc->setWidth(binSize*0.2); ohlc->setTwoColored(true); // create bottom axis rect for volume bar chart: QCPAxisRect *volumeAxisRect = new QCPAxisRect(this); plotLayout()->addElement(1, 0, volumeAxisRect); volumeAxisRect->setMaximumSize(QSize(QWIDGETSIZE_MAX, 100)); volumeAxisRect->axis(QCPAxis::atBottom)->setLayer("axes"); volumeAxisRect->axis(QCPAxis::atBottom)->grid()->setLayer("grid"); // bring bottom and main axis rect closer together: plotLayout()->setRowSpacing(0); volumeAxisRect->setAutoMargins(QCP::msLeft|QCP::msRight|QCP::msBottom); volumeAxisRect->setMargins(QMargins(0, 0, 0, 0)); // create two bar plottables, for positive (green) and negative (red) volume bars: QCPBars *volumePos = new QCPBars(volumeAxisRect->axis(QCPAxis::atBottom), volumeAxisRect->axis(QCPAxis::atLeft)); QCPBars *volumeNeg = new QCPBars(volumeAxisRect->axis(QCPAxis::atBottom), volumeAxisRect->axis(QCPAxis::atLeft)); for (int i=0; i<n/5; ++i) { int v = qrand()%20000+qrand()%20000+qrand()%20000-10000*3; (v < 0 ? volumeNeg : volumePos)->addData(startTime+3600*5.0*i, qAbs(v)); // add data to either volumeNeg or volumePos, depending on sign of v } setAutoAddPlottableToLegend(false); addPlottable(volumePos); addPlottable(volumeNeg); volumePos->setWidth(3600*4); volumePos->setPen(Qt::NoPen); volumePos->setBrush(QColor(100, 180, 110)); volumeNeg->setWidth(3600*4); volumeNeg->setPen(Qt::NoPen); volumeNeg->setBrush(QColor(180, 90, 90)); // interconnect x axis ranges of main and bottom axis rects: connect(xAxis, SIGNAL(rangeChanged(QCPRange)), volumeAxisRect->axis(QCPAxis::atBottom), SLOT(setRange(QCPRange))); connect(volumeAxisRect->axis(QCPAxis::atBottom), SIGNAL(rangeChanged(QCPRange)), xAxis, SLOT(setRange(QCPRange))); // configure axes of both main and bottom axis rect: volumeAxisRect->axis(QCPAxis::atBottom)->setAutoTickStep(false); volumeAxisRect->axis(QCPAxis::atBottom)->setTickStep(3600*24*4); // 4 day tickstep volumeAxisRect->axis(QCPAxis::atBottom)->setTickLabelType(QCPAxis::ltDateTime); volumeAxisRect->axis(QCPAxis::atBottom)->setDateTimeSpec(Qt::UTC); volumeAxisRect->axis(QCPAxis::atBottom)->setDateTimeFormat("dd. MMM"); volumeAxisRect->axis(QCPAxis::atBottom)->setTickLabelRotation(15); volumeAxisRect->axis(QCPAxis::atLeft)->setAutoTickCount(3); xAxis->setBasePen(Qt::NoPen); xAxis->setTickLabels(false); xAxis->setTicks(false); // only want vertical grid in main axis rect, so hide xAxis backbone, ticks, and labels xAxis->setAutoTickStep(false); xAxis->setTickStep(3600*24*4); // 4 day tickstep rescaleAxes(); xAxis->scaleRange(1.025, xAxis->range().center()); yAxis->scaleRange(1.1, yAxis->range().center()); // make axis rects' left side line up: QCPMarginGroup *group = new QCPMarginGroup(this); axisRect()->setMarginGroup(QCP::msLeft|QCP::msRight, group); volumeAxisRect->setMarginGroup(QCP::msLeft|QCP::msRight, group); }
void Reportes::inicializarGraficoMuestras() { graficoMuestras->plotLayout()->clear(); // let's start from scratch and remove the default axis rect graficoMuestras->clearItems(); graficoMuestras->clearGraphs(); //Se crean los LAYOUTS principales QCPLayoutGrid *layoutAcelerometro = new QCPLayoutGrid; QCPLayoutGrid *layoutGiroscopio = new QCPLayoutGrid; //Se crean los titulos QCPPlotTitle *tituloAcelerometro = new QCPPlotTitle(graficoMuestras, "Gráficos Aceleración X Y Z vs Tiempo"); QCPPlotTitle *tituloGiroscopio = new QCPPlotTitle(graficoMuestras, "Gráficos Velocidad Angular X Y Z vs Tiempo"); //Se añaden los layouts principales y los titulos graficoMuestras->plotLayout()->addElement(0, 0, tituloAcelerometro); graficoMuestras->plotLayout()->addElement(1, 0, layoutAcelerometro); graficoMuestras->plotLayout()->addElement(2, 0, tituloGiroscopio); graficoMuestras->plotLayout()->addElement(3, 0, layoutGiroscopio); // Se crean los sublayouts del acelerometro QCPAxisRect *leftAxisRectAcelerometro = new QCPAxisRect(graficoMuestras); QCPAxisRect *centerAxisRectAcelerometro = new QCPAxisRect(graficoMuestras); QCPAxisRect *rightAxisRectAcelerometro = new QCPAxisRect(graficoMuestras); //Se agregan al layout principal layoutAcelerometro->addElement(0, 0, leftAxisRectAcelerometro); layoutAcelerometro->addElement(0, 1, centerAxisRectAcelerometro); layoutAcelerometro->addElement(0, 2, rightAxisRectAcelerometro); //Se crean los sublayouts del giroscopio QCPAxisRect *leftAxisRectGiroscopio = new QCPAxisRect(graficoMuestras); QCPAxisRect *centerAxisRectGiroscopio = new QCPAxisRect(graficoMuestras); QCPAxisRect *rightAxisRectGiroscopio = new QCPAxisRect(graficoMuestras); //Se agregan al layout principal layoutGiroscopio->addElement(0, 0, leftAxisRectGiroscopio); layoutGiroscopio->addElement(0, 1, centerAxisRectGiroscopio); layoutGiroscopio->addElement(0, 2, rightAxisRectGiroscopio); // create and configure plottables: Acelerometro graficoAcX = graficoMuestras->addGraph(leftAxisRectAcelerometro->axis(QCPAxis::atBottom), leftAxisRectAcelerometro->axis(QCPAxis::atLeft)); graficoAcY = graficoMuestras->addGraph(centerAxisRectAcelerometro->axis(QCPAxis::atBottom), centerAxisRectAcelerometro->axis(QCPAxis::atLeft)); graficoAcZ = graficoMuestras->addGraph(rightAxisRectAcelerometro->axis(QCPAxis::atBottom), rightAxisRectAcelerometro->axis(QCPAxis::atLeft)); // create and configure plottables: Giroscopio graficoGyX = graficoMuestras->addGraph(leftAxisRectGiroscopio->axis(QCPAxis::atBottom), leftAxisRectGiroscopio->axis(QCPAxis::atLeft)); graficoGyY = graficoMuestras->addGraph(centerAxisRectGiroscopio->axis(QCPAxis::atBottom), centerAxisRectGiroscopio->axis(QCPAxis::atLeft)); graficoGyZ = graficoMuestras->addGraph(rightAxisRectGiroscopio->axis(QCPAxis::atBottom), rightAxisRectGiroscopio->axis(QCPAxis::atLeft)); // Lineas para el analisis lineaIzqAcX=new QCPItemLine(graficoMuestras); agregarQCPItemLine(lineaIzqAcX,graficoMuestras,leftAxisRectAcelerometro); lineaDerAcX=new QCPItemLine(graficoMuestras); agregarQCPItemLine(lineaDerAcX,graficoMuestras,leftAxisRectAcelerometro); lineaIzqAcY=new QCPItemLine(graficoMuestras); agregarQCPItemLine(lineaIzqAcY,graficoMuestras,centerAxisRectAcelerometro); lineaDerAcY=new QCPItemLine(graficoMuestras); agregarQCPItemLine(lineaDerAcY,graficoMuestras,centerAxisRectAcelerometro); lineaIzqAcZ=new QCPItemLine(graficoMuestras); agregarQCPItemLine(lineaIzqAcZ,graficoMuestras,rightAxisRectAcelerometro); lineaDerAcZ=new QCPItemLine(graficoMuestras); agregarQCPItemLine(lineaDerAcZ,graficoMuestras,rightAxisRectAcelerometro); lineaIzqGyX=new QCPItemLine(graficoMuestras); agregarQCPItemLine(lineaIzqGyX,graficoMuestras,leftAxisRectGiroscopio); lineaDerGyX=new QCPItemLine(graficoMuestras); agregarQCPItemLine(lineaDerGyX,graficoMuestras,leftAxisRectGiroscopio); lineaIzqGyY=new QCPItemLine(graficoMuestras); agregarQCPItemLine(lineaIzqGyY,graficoMuestras,centerAxisRectGiroscopio); lineaDerGyY=new QCPItemLine(graficoMuestras); agregarQCPItemLine(lineaDerGyY,graficoMuestras,centerAxisRectGiroscopio); lineaIzqGyZ=new QCPItemLine(graficoMuestras); agregarQCPItemLine(lineaIzqGyZ,graficoMuestras,rightAxisRectGiroscopio); lineaDerGyZ=new QCPItemLine(graficoMuestras); agregarQCPItemLine(lineaDerGyZ,graficoMuestras,rightAxisRectGiroscopio); //Estilo del lapiz para la linea graficoAcX->setPen(QPen(Qt::blue)); graficoAcY->setPen(QPen(Qt::blue)); graficoAcZ->setPen(QPen(Qt::blue)); graficoGyX->setPen(QPen(QColor(153, 102, 51), 2)); graficoGyY->setPen(QPen(QColor(153, 102, 51), 2)); graficoGyZ->setPen(QPen(QColor(153, 102, 51), 2)); //Labels de los ejes: Acelerometro leftAxisRectAcelerometro->axis(QCPAxis::atLeft)->setLabel("Aceleracion Eje X (G)"); leftAxisRectAcelerometro->axis(QCPAxis::atBottom)->setLabel("Tiempo (segundos)"); centerAxisRectAcelerometro->axis(QCPAxis::atLeft)->setLabel("Aceleracion Eje Y (G)"); centerAxisRectAcelerometro->axis(QCPAxis::atBottom)->setLabel("Tiempo (segundos)"); rightAxisRectAcelerometro->axis(QCPAxis::atLeft)->setLabel("Aceleracion Eje Z (G)"); rightAxisRectAcelerometro->axis(QCPAxis::atBottom)->setLabel("Tiempo (segundos)"); //Labels de los ejes: Giroscopio leftAxisRectGiroscopio->axis(QCPAxis::atLeft)->setLabel("Velocidad Angular Eje X (º/segundos)"); leftAxisRectGiroscopio->axis(QCPAxis::atBottom)->setLabel("Tiempo (segundos)"); centerAxisRectGiroscopio->axis(QCPAxis::atLeft)->setLabel("Velocidad Angular Eje Y (º/segundos)"); centerAxisRectGiroscopio->axis(QCPAxis::atBottom)->setLabel("Tiempo (segundos)"); rightAxisRectGiroscopio->axis(QCPAxis::atLeft)->setLabel("Velocaidad Angular Eje Z (º/segundos)"); rightAxisRectGiroscopio->axis(QCPAxis::atBottom)->setLabel("Tiempo (segundos)"); //Agregamos interactividad graficoMuestras->setInteractions(QCP::iRangeDrag|QCP::iRangeZoom); //grafico->replot(); //Se redibuja para actualizar la vista }
void MainWindow::setupItemTracerTest_MyTest_2(QCustomPlot *customPlot) { QCPAxisRect* pAxisRectTop = NULL; QCPAxisRect* pAxisRectBottom = NULL; QCPLayoutGrid *pLayoutGrid = NULL; QCPMarginGroup *pMarginGroup = NULL; QCPItemTracerCrossHair *pTracerTop = NULL; QCPItemTracerCrossHair *pTracerBottom = NULL; CMidSubDrawHelper* m_pMidSubDrawHelper = NULL; CHistoryDataManager* pHistoryDataManager = NULL; customPlot->clearGraphs(); customPlot->plotLayout()->clear(); // clear default axis rect so we can start from scratch pAxisRectTop = new QCPAxisRect(customPlot); pAxisRectTop->setupFullAxesBox(true); pAxisRectTop->axis(QCPAxis::atLeft)->setLabel(QObject::tr("Y-value")); pAxisRectTop->axis(QCPAxis::atBottom)->setLabel(QObject::tr("X-time")); pAxisRectTop->axis(QCPAxis::atBottom)->setTickLabelType(QCPAxis::ltDateTime); pAxisRectTop->axis(QCPAxis::atBottom)->setDateTimeFormat(DEF_STRING_FORMAT_TIME.c_str()); pAxisRectBottom = new QCPAxisRect(customPlot); pAxisRectBottom->setupFullAxesBox(true); pAxisRectBottom->axis(QCPAxis::atLeft)->setLabel(QObject::tr("Y-value")); pAxisRectBottom->axis(QCPAxis::atBottom)->setLabel(QObject::tr("X-time")); pAxisRectBottom->axis(QCPAxis::atBottom)->setTickLabelType(QCPAxis::ltDateTime); pAxisRectBottom->axis(QCPAxis::atBottom)->setDateTimeFormat(DEF_STRING_FORMAT_TIME.c_str());//("yyyy-MM-dd hh-mm-ss"); customPlot->plotLayout()->addElement(0, 0, pAxisRectTop); // insert axis rect in first row customPlot->plotLayout()->addElement(1, 0, pAxisRectBottom); // insert axis rect in first row pLayoutGrid = customPlot->plotLayout(); pMarginGroup = new QCPMarginGroup(customPlot); pLayoutGrid->element(0, 0)->setMarginGroup(QCP::msAll, pMarginGroup); pLayoutGrid->element(1, 0)->setMarginGroup(QCP::msAll, pMarginGroup); m_pMidSubDrawHelper = new CMidSubDrawHelper(); pHistoryDataManager = new CHistoryDataManager(); m_pMidSubDrawHelper->drawHistoryBarData(pHistoryDataManager, customPlot, pAxisRectTop); m_pMidSubDrawHelper->drawHistoryVolumeData(pHistoryDataManager, customPlot, pAxisRectBottom); //setupItemTracerTest_MyTest_addGrap(customPlot, pAxisRectTop); //setupItemTracerTest_MyTest_addGrap(customPlot, pAxisRectBottom); pTracerTop = NULL; pTracerTop = new QCPItemTracerCrossHair(customPlot); customPlot->addItem(pTracerTop); pTracerTop->setTracerAxisRect(pAxisRectTop); pTracerTop->setStyle(QCPItemTracerCrossHair::tsCrosshair); pTracerTop->setShowLeft(QCPAxis::ltNumber, true, QString("")); pTracerTop->setShowBottom(QCPAxis::ltDateTime, true, QString(DEF_STRING_FORMAT_TIME.c_str())); m_pQCPItemTracerCrossHairTop = pTracerTop; pTracerBottom = NULL; pTracerBottom = new QCPItemTracerCrossHair(customPlot); customPlot->addItem(pTracerBottom); pTracerBottom->setTracerAxisRect(pAxisRectBottom); pTracerBottom->setStyle(QCPItemTracerCrossHair::tsCrosshair); pTracerBottom->setShowLeft(QCPAxis::ltNumber, true, QString("")); pTracerBottom->setShowBottom(QCPAxis::ltDateTime, true, QString(DEF_STRING_FORMAT_TIME.c_str())); m_pQCPItemTracerCrossHairBottom = pTracerBottom; connect(customPlot, SIGNAL(mouseMove(QMouseEvent*)), this, SLOT(QCPItemTracerCrossHairMouseMove(QMouseEvent*))); //customPlot->rescaleAxes(); customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); customPlot->replot();//draw again if (NULL != m_pMidSubDrawHelper) { delete m_pMidSubDrawHelper; m_pMidSubDrawHelper = NULL; } if (NULL != pHistoryDataManager) { delete pHistoryDataManager; pHistoryDataManager = NULL; } }
void MainWindow::setupItemTracerTest_MyTest_1(QCustomPlot *customPlot) { QCPAxisRect* pAxisRectTop = NULL; QCPAxisRect* pAxisRectBottom = NULL; QCPLayoutGrid *pLayoutGrid = NULL; QCPMarginGroup *pMarginGroup = NULL; QCPItemTracerCrossHair *pTracerTop = NULL; QCPItemTracerCrossHair *pTracerBottom = NULL; customPlot->clearGraphs(); customPlot->plotLayout()->clear(); // clear default axis rect so we can start from scratch pAxisRectTop = new QCPAxisRect(customPlot); pAxisRectTop->setupFullAxesBox(true); //pAxisRectTop->axis(QCPAxis::atLeft)->setLabel(QObject::tr("Y-value")); //pAxisRectTop->axis(QCPAxis::atBottom)->setLabel(QObject::tr("X-time")); //pAxisRectTop->axis(QCPAxis::atBottom)->setTickLabelType(QCPAxis::ltDateTime); //pAxisRectTop->axis(QCPAxis::atBottom)->setDateTimeFormat("yyyy-MM-dd hh-mm-ss");//DEF_STRING_FORMAT_TIME pAxisRectBottom = new QCPAxisRect(customPlot); pAxisRectBottom->setupFullAxesBox(true); //pAxisRectBottom->axis(QCPAxis::atLeft)->setLabel(QObject::tr("Y-value")); //pAxisRectBottom->axis(QCPAxis::atBottom)->setLabel(QObject::tr("X-time")); //pAxisRectBottom->axis(QCPAxis::atBottom)->setTickLabelType(QCPAxis::ltDateTime); //pAxisRectBottom->axis(QCPAxis::atBottom)->setDateTimeFormat("yyyy-MM-dd hh-mm-ss");//DEF_STRING_FORMAT_TIME customPlot->plotLayout()->addElement(0, 0, pAxisRectTop); // insert axis rect in first row customPlot->plotLayout()->addElement(1, 0, pAxisRectBottom); // insert axis rect in first row pLayoutGrid = customPlot->plotLayout(); pMarginGroup = new QCPMarginGroup(customPlot); pLayoutGrid->element(0, 0)->setMarginGroup(QCP::msAll, pMarginGroup); pLayoutGrid->element(1, 0)->setMarginGroup(QCP::msAll, pMarginGroup); QCPGraph *graph = customPlot->addGraph(pAxisRectTop->axis(QCPAxis::atBottom), pAxisRectTop->axis(QCPAxis::atLeft)); int n = 200; QVector<double> x(n), y(n); for (int i=0; i<n; ++i) { x[i] = 0.5+i/(double)n*4; y[i] = qSin(x[i])+1.5; } graph->setData(x, y); pTracerTop = NULL; pTracerTop = new QCPItemTracerCrossHair(customPlot); customPlot->addItem(pTracerTop); pTracerTop->setTracerAxisRect(pAxisRectTop); pTracerTop->setStyle(QCPItemTracerCrossHair::tsCrosshair); m_pQCPItemTracerCrossHairTop = pTracerTop; pTracerBottom = NULL; pTracerBottom = new QCPItemTracerCrossHair(customPlot); customPlot->addItem(pTracerBottom); pTracerBottom->setTracerAxisRect(pAxisRectBottom); pTracerBottom->setStyle(QCPItemTracerCrossHair::tsCrosshair); m_pQCPItemTracerCrossHairBottom = pTracerBottom; connect(customPlot, SIGNAL(mouseMove(QMouseEvent*)), this, SLOT(QCPItemTracerCrossHairMouseMove(QMouseEvent*))); customPlot->rescaleAxes(); customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); customPlot->replot();//draw again }