簡體   English   中英

QCustomPlot 在軸上的垂直線

[英]QCustomPlot vertical line at axis

我正在使用 Qt 使用 QCustomPlot 並且需要更改圖表中特定垂直網格線的顏色,請讓我們知道如何更改我附加了我的要求的圖像。

在此處輸入圖像描述

bleo代碼解決了這個問題

GraphTesting(QCustomPlot * customPlot)
{
    // generate some data:
    QVector<double> x(101), y(101); // initialize with entries 0..100
    for (int i = 0; i < 101; ++i)
    {
        x[i] = i; //i / 50.0 - 1; // x goes from -1 to 1
        y[i] = x[i]/2; // let's plot a quadratic function
    }
    // create graph and assign data to it:

    
    customPlot->addGraph();
    customPlot->graph(0)->setData(x, y);
    
    // give the axes some labels:
    customPlot->xAxis->setLabel("x");
    customPlot->yAxis->setLabel("y");
    customPlot->rescaleAxes();

    QCPItemLine *step = new QCPItemLine(customPlot);
    step->setPen(QPen(QColor(140, 0, 0)));

    double begin = 25;
    double first = customPlot->yAxis->range().lower;
    double end = customPlot->yAxis->range().upper;   //example values

    step->start->setCoords(begin, first);
    step->end->setCoords(begin, end);
    customPlot->replot();
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM