贴一个上次说的customplot画图显示value的代码

对上次画柱状图显示valu的代码补充
void QCPBars::draw(QCPPainter *painter)
{
if (!mKeyAxis || !mValueAxis) { qDebug() << Q_FUNC_INFO << “invalid key or value axis”; return; }
if (mDataContainer->isEmpty()) return;

QCPBarsDataContainer::const_iterator visibleBegin, visibleEnd;
getVisibleDataBounds(visibleBegin, visibleEnd);

// loop over and draw segments of unselected/selected data:
QList selectedSegments, unselectedSegments, allSegments;
getDataSegments(selectedSegments, unselectedSegments);
allSegments << unselectedSegments << selectedSegments;
for (int i=0; i<allSegments.size(); ++i)
{
bool isSelectedSegment = i >= unselectedSegments.size();
QCPBarsDataContainer::const_iterator begin = visibleBegin;
QCPBarsDataContainer::const_iterator end = visibleEnd;
mDataContainer->limitIteratorsToDataRange(begin, end, allSegments.at(i));
if (begin == end)
continue;
for (QCPBarsDataContainer::const_iterator it=begin; it!=end; ++it)
{
// check data validity if flag set:
#ifdef QCUSTOMPLOT_CHECK_DATA
if (QCP::isInvalidData(it->key, it->value))
qDebug() << Q_FUNC_INFO << “Data point at” << it->key << “of drawn range invalid.” << “Plottable name:” << name();
#endif
// draw bar:
if (isSelectedSegment && mSelectionDecorator)
{
mSelectionDecorator->applyBrush(painter);
mSelectionDecorator->applyPen(painter);
} else
{
painter->setBrush(mBrush);
painter->setPen(mPen);
}
applyDefaultAntialiasingHint(painter);
painter->drawPolygon(getBarRect(it->key, it->value));
// painter->setPen(QColor(Qt::white));

		QPen pen;
    	  pen.setWidth(1);
    	  pen.setBrush(Qt::white);
    	  pen.setJoinStyle(Qt::RoundJoin);
    	  pen.setCapStyle(Qt::RoundCap);
    	  painter->setPen(pen);
    	  int range = 0;
    	  if(it->value >= 0 && it->value < 0.5)
    	  {
    		  range = -5;
    	  }
    	  else
    	  {
    		  range = 10;
    	  }
    	  painter->drawText(getBarRect(it->key, it->value).x()+3, getBarRect(it->key, it-   >value).y()+range, QString::number(it->value, 'f', 2));

}
}

// draw other selection decoration that isn’t just line/scatter pens and brushes:
if (mSelectionDecorator)
mSelectionDecorator->drawDecoration(painter, selection());
}
阿斯蒂芬在这里插入图片描述
上图就是设置value的显示,customplot.cpp中没有对这个value的显示做封装,所以直接修改这个函数就可以,需要其他图的也可以在相应的draw函数中修改。

  • 7
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 26
    评论
评论 26
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值