首页 > 其他分享 >QCustomPlot绘制股票曲线,去除中间休市时间

QCustomPlot绘制股票曲线,去除中间休市时间

时间:2024-08-10 14:49:17浏览次数:8  
标签:xAxis 1800 去除 QCustomPlot 休市 ui starttime time NGragh

QCPAxis中增加两个函数,设置x轴的值和标签映射关系,要把中午午休的时间去掉;

 

void setTickVector(QVector<double> tickVector) { mTickVector = tickVector; };

void setTickLabels(QVector<QString> tickLabel ) { mTickVectorLabels= tickLabel; }

void NGraph::SetXTimeLabel(QString strTimeFormat)
{
    //ui.NGragh->xAxis->setTickLabelType(QCPAxis::ltDateTime);
    //ui.NGragh->xAxis->setDateTimeFormat(strTimeFormat);
    //ui.NGragh->xAxis->setDateTimeSpec(Qt::LocalTime);
    //QSharedPointer<QCPAxisTickerDateTime> dateTimeTicker(new QCPAxisTickerDateTime);
    //dateTimeTicker->setDateTimeFormat(strTimeFormat);
    //dateTimeTicker->setDateTimeSpec(Qt::LocalTime);
    //ui.NGragh->xAxis->setTicker(dateTimeTicker);
    ui.NGragh->xAxis->setFixTickLabel(true);
    ui.NGragh->xAxis->setTickLabels(true); // 不显示这一段的刻度标签
    ui.NGragh->xAxis->setSubTicks(false);  // 不显示子刻度
    QTime time=QTime::fromString("0930", "hhmm");
    double starttime= time.hour()*3600+ time.minute()*60;
    ui.NGragh->xAxis->setTickVector(QVector<double>({ starttime,starttime +1800,starttime+1800*2,starttime+1800*3,starttime+1800*4,starttime+1800*5,starttime + 1800 *6,starttime + 1800 *7,starttime + 1800 * 8 }));
    ui.NGragh->xAxis->setTickLabels(QVector<QString>({"09:30","10:00","1030","11:00","11:30","13:30","14:00","14:30","15:00"}));
}

因为会自动生成坐标轴,所以需要再顶一个个变量,设置固定坐标轴

  ui.NGragh->xAxis->setFixTickLabel(true);
 void setFixTickLabel(bool fix) { mbFixTickLabel = fix; };
然后在生成坐标轴的地方加上判断,如果设置了true,则不自动生成标签
void QCPAxis::setupTickVectors()
{
  if (!mParentPlot) return;
  if ((!mTicks && !mTickLabels && !mGrid->visible()) || mRange.size() <= 0) return;
  if (mbFixTickLabel == false)
  {
      QVector<QString> oldLabels = mTickVectorLabels;
      mTicker->generate(mRange, mParentPlot->locale(), mNumberFormatChar, mNumberPrecision, mTickVector, mSubTicks ? &mSubTickVector : nullptr, mTickLabels ? &mTickVectorLabels : nullptr);
      mCachedMarginValid &= mTickVectorLabels == oldLabels; // if labels have changed, margin might have changed, too
  }
}

 

最后在生成数据的地方,如果是下午时间,则自动减去中午的休市的1个半小时,也就是5400秒,也是时间值前移5400秒,去掉休市时间,标签值映射关系则是向后移;这样看起来中间没有中断,而且时间标签也能对的上
if (it != m_mapMiniteData.end())
    {
        
        QVariantList listdata = it.value().value("listdata").toList();
        QVector<double> x, y;
        for (int i = 0; i < listdata.size(); i++)
        {
            if (listdata[i].toMap().value("time").toString() >= "1300")
            {
                QTime  time = QTime::fromString(listdata[i].toMap().value("time").toString(), "hhmm").addSecs(-5400);
                x.push_back(time.hour() * 3600 + time.minute() * 60);
            }
            else
            {
                QTime  time = QTime::fromString(listdata[i].toMap().value("time").toString(), "hhmm");
                x.push_back(time.hour() * 3600 + time.minute() * 60);
            }
            y.push_back(listdata[i].toMap().value("price").toDouble());
        }
        m_Graph.hide();
        m_Graph.SetData(0, x, y);
        m_Graph.show();
    }

 



标签:xAxis,1800,去除,QCustomPlot,休市,ui,starttime,time,NGragh
From: https://www.cnblogs.com/bclshuai/p/18352279

相关文章

  • 开源的一键AI去除视频水印和字幕!
    【大华轻创】大家好,我是大华!我们做网创的,多多少少会去下载很多视频素材,但很多素材自己觉得非常好,但有那该死的水印和字幕就让人非常不爽,要么在剪辑的时候放大把字幕拉出屏幕外,又或者是用黑框该掉字幕,这着实影响美观!有什么办法可以直接去掉字幕和水印吗?答案是有的!今天就......
  • 如何去除Win10的激活水印
    在使用Win10系统时会遇到各种问题,不知道该怎么解决,有部分用户安装了Win10系统后右下角会提示有未激活的水印,看起来很不舒服,其实解决方法很简单:1)在桌面新建一个文本文档,把以下代码复制进去,如图所示: slmgr/ipkW269N-WFGWX-YVC9B-4J6C9-T83GXslmgr/skmskms.03k.org......
  • String类的其他功能,替换、去除空格、比较字符串相等 day11
    packagecom.shujia.day11;/*String类的其他功能:替换功能Stringreplace(charold,charnew)将字符串中所有的旧字符使用新字符进行替换,返回新的字符串Stringreplace(Stringold,Stringnew)将字符串中所有的旧字符串使用新......
  • 文本分词加停用词去除
    importosimportjiebadefload_stopwords(stopwords_path):"""加载停用词表"""withopen(stopwords_path,'r',encoding='utf-8')asfile:stopwords=set(file.read().split())returnstopwords......
  • ZeRO:一种去除冗余的数据并行方案
    ZeRO:一种去除冗余的数据并行方案目前训练超大规模语言模型主要有两条技术路线:TPU+XLA+TensorFlow/JAXGPU+Pytorch+Megatron+DeepSpeed前者由Google主导,由于TPU和自家云平台GCP深度绑定,对于非Googler来说并不友好后者背后则有NVIDIA、Meta、MS等大厂加持,社区氛围活......
  • 易优cms在phpstudy环境下,可以去除:/index.php?/guanyuwomen/ 中的index.php吗
    针对不同服务器、虚拟空间,运行PHP的环境也有所不同,目前主要分为:Nginx、apache、IIS以及其他服务器。下面分享如何去掉URL上的index.php字符,记得在管理后台清除缓存,对于一些ECS服务器可能要重启nginx等服务!【IIS服务器】可以移步,《iis怎么去掉index.php》【Nginx服务器】在......
  • 使用油候脚本,去除博客园的广告
    最近不知道博客园是否加入广告了,发现浏览的时候,在页面顶端会有占很大区域的广告,先试试代码://==UserScript==//@name去除博客园顶部的广告//@namespacehttp://tampermonkey.net///@version0.1//@descriptiontrytotakeovertheworld!//@autho......
  • QCustomPlot绘制热力图
    绘制的热力图类似以下,后面代码可以直接去使用。//在QCustomPlot中创建图像QCustomPlot*myCustomPlot=newQCustomPlot();ui->verticalLayout->addWidget(myCustomPlot);//向量大小为3787*6132intxMax=6132;intyMax=3787;Ei......
  • 易优cms空间安装易优,如何去除URL中的index.php
    普遍适用于百度云虚拟主机百度云bch云主机支持nginx原生态伪静态规则写法,请将规则写到/webroot/目录下的bcloud_nginx_user.conf文件中(没有则创建),重载站点生效。首先我们写一个bcloud_nginx_user.conf文件,写入一下代码:location/{  if(!-e$request_filename){    ......
  • 使用Python去除图像中的线条
    我正在尝试使用Python和cv2、numpy、skimage等从黑白图像中删除“阴影线”(如果图像中存在“阴影线”)。本质上,我的图像可以有1或2条曲线,如下例所示。但每条线都有一条1-5像素外的阴影线,需要删除。我怎样才能在Python中做到这一点?原始......