为了抛弃对QChart的依赖,以及echart的依赖,(当然,后期也会做qchart的版本和echart的版本,尤其是echart的版本是肯定会做的,毕竟echart的效果牛逼的一塌糊涂,全宇宙最牛逼吧。)特意对QCustomPlot进行了大刀阔斧的改造,当然这个改造不是直接在源码上修改,这个就破坏了源码的完整性,说不定被QCustomPlot的作者知道了有种被QJ的感觉,我得改造是直接继承QCustomPlot中的部分类开始的,比如为了实现横向柱状图,特意继承自QCPItemRect类来实现的,包括了横向柱状图和横向柱状分组图。在这个横向柱状图的自动计算过程中,居然用到了十几年前学习的二元一次方程,自动计算数据和柱状图位置,给定两个数据点绘制矩形。
QCustomPlot类做的非常好,作者将曲线图和柱状图和其他几种形状的图,玩得神乎其神,本人直接跪了。尤其是现在的2.0版本,比以前的1.0版本更加上了一个档次,直接将各种功能拆分成一个个小类,分层绘制,相当牛逼,比如要做个游标,直接继承QCPLayerable类,然后在void draw(QCPPainter *painter);中绘制自己的东西即可,QCustomPlot提供了一个非常完美的鼠标拉动缩放的二维坐标系,还有对应的坐标与屏幕坐标转换的函数,继承自QCPItemRect这个东东,可以任意绘制任意图形,包括圆形矩形各种,本人有个大胆的想法就是,直接将那145个控件大全控件在QCustomPlot中绘制一遍,都是完全可行的,这样的话还支持滚轮任意缩放呢。
电子看板是目视化管理的一种表现形式,即对数据的状况一目了然地表现,主要是对于管理项目,它通过利用形象直观而又色彩适宜的各种视觉感知信息来组织现场生产活动,目视管理依据人类的生理特征,在生产现场充分利用信号灯、标识牌、符号颜色等方式来发出视觉信号,鲜明准确地刺激人的神经末梢,快速地传递信息,形象直观地将潜在的问题和浪费现象都显现出来。以便任何人都可以及时掌握管理现状和必要的情报,从而能够快速制定并实施应对措施。因此,管理看板是发现问题、解决问题的非常有效且直观的手段,是优秀的现场管理必不可少的工具之一。
void CustomPlot::mouseMove(QMouseEvent *event)
{
if (tracer == 0 || textTip == 0) {
return;
}
//跟踪鼠标点击事件点击位置
QCPGraph *graph = (QCPGraph *)customPlot->plottableAt(event->pos(), true);
QRect rect(0, 0, 1, 1);
QString labx, laby;
int offset = 10;
bool toolTip = false;
if(graph != 0) {
double posKey;
double key = 0, value = 0;
QPoint p;
p.setX(event->pos().x());
p.setY(event->pos().y());
#ifdef old
foreach(QCPData data, graph->data()->values()) {
key = data.key;
value = data.value;
#else
for (int i = 0; i < graph->dataCount(); i++) {
key = graph->dataMainKey(i);
value = graph->dataMainValue(i);
#endif
//取出对应key处的label标签,如果标签为空则取key的字符串
labx = customPlot->xAxis->tickVectorLabels().at(key);
labx = labx.isEmpty() ? QString::number(key) : labx;
//如果启用了百分比则需要后面显示百分比
if (this->getPercentY()) {
laby = QString("%1%").arg(value);
} else {
laby = QString("%1").arg(value);
}
posKey = customPlot->xAxis->coordToPixel(key);
if(qAbs(posKey - event->pos().x()) <= offset) {
double posx = graph->keyAxis()->coordToPixel(key);
double posy = graph->valueAxis()->coordToPixel(value);
rect.setRect(posx - offset, posy - offset, offset * 2, offset * 2);
if(!rect.contains(event->pos())) {
continue;
} else {
break;
}
}
if(posKey - event->pos().x() > offset) {
break;
}
}
if(!graph->realVisibility()) {
toolTip = false;
tracer->setVisible(false);
customPlot->replot();
} else if(rect.contains(event->pos())) {
toolTip = true;
tracer->setVisible(true);
tracer->setGraph(graph);
tracer->setGraphKey(key);
customPlot->replot();
} else if(tracer->visible()) {
toolTip = false;
tracer->setVisible(false);
customPlot->replot();
}
}
else if(tracer->visible()) {
toolTip = false;
tracer->setVisible(false);
customPlot->replot();
}
//处理提示信息
if(toolTip) {
//根据设定的提示信息位置调整
double x = event->pos().x();
double y = event->pos().y();
if (toolTipPosition == 0) {
//判断曲线控件的位置已经当前鼠标位置做出调整
bool right = (customPlot->width() - x < 90);
bool bottom = (customPlot->height() - y < 50);
if (right) {
if (bottom) {
x = x - 80;
y = y - 50;
} else {
x = x - 80;
y = y - 20;
}
} else {
if (bottom) {
x = x + 10;
y = y - 50;
} else {
x = x + 10;
y = y - 20;
}
}
} else if (toolTipPosition == 1) {
x = x - 30;
y = y - 50;
} else if (toolTipPosition == 2) {
x = x + 10;
y = y - 50;
} else if (toolTipPosition == 3) {
x = x + 10;
y = y - 20;
} else if (toolTipPosition == 4) {
x = x + 10;
y = y + 10;
} else if (toolTipPosition == 5) {
x = x - 30;
y = y + 10;
} else if (toolTipPosition == 6) {
x = x - 75;
y = y + 10;
} else if (toolTipPosition == 7) {
x = x - 80;
y = y - 20;
} else if (toolTipPosition == 8) {
x = x - 80;
y = y - 50;
}
QString text = "横坐标: " + labx + "\n当前值: " + laby;
textTip->position->setCoords(x, y);
textTip->setText(text);
textTip->setVisible(true);
customPlot->replot();
} else {
if (textTip->visible()) {
textTip->setVisible(false);
customPlot->replot();
}
}
}
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。