简体   繁体   English

QCustomPlot 在轴上的垂直线

[英]QCustomPlot vertical line at axis

I am working QCustomPlot with Qt and need to change the color of a particular vertical grid line within the graph please let us know how we can change that I attached the image of my requirement.我正在使用 Qt 使用 QCustomPlot 并且需要更改图表中特定垂直网格线的颜色,请让我们知道如何更改我附加了我的要求的图像。

在此处输入图像描述

The bleo code solve the issue 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