油田电泵井电流卡片坐标系的绘制(QML canvas)

1 篇文章 0 订阅
1 篇文章 0 订阅

总是在网络上搜索、学习,感恩各位大佬们的无私奉献。
电泵卡片能直接反映泵的工况,虽然电流曲线可以用直角坐标系中的曲线来展示(比如用eChart等),但现场的技术人员还是喜欢看传统的圆形坐标系中的曲线,这可怎么办,于是琢磨了起来。
各种圆,仔细看吧,我是想了好一段时间才整明白
下面直接上代码吧,我用的是QML+webassembly,当然纯网页也基本可以用,请参考。

import QtQuick 2.12
import QtQuick.Window 2.12

Window {
    id: win
    width: 300
    height: 300
    visible: true

    Canvas {
        id: root;
        width: win.width;
        height: win.height;

        onPaint: {
            var ctx = getContext("2d");
            if(win.width > win.height){     //以宽高最小的数值为图的尺寸
                width = win.height
                height = win.height
            }else{
                width = win.width
                height = win.width
            }

            var xWMin = width / 70 //电流坐标的细线
            ctx.lineWidth = 1;
            ctx.strokeStyle = "#697279";
            ctx.fillStyle = "red";
            ctx.save();
            ctx.translate(width/2,height/2);
            for(var i = xWMin * 5; i < xWMin*26; i = i + xWMin*5)
            {
                ctx.beginPath();
                ctx.arc(0,0,i,0,Math.PI*2);
                ctx.stroke();
                ctx.beginPath();
                ctx.arc(0,0,i+xWMin,0,Math.PI*2);
                ctx.stroke();
                ctx.beginPath();
                ctx.arc(0,0,i+xWMin*2,0,Math.PI*2);
                ctx.stroke();
                ctx.beginPath();
                ctx.arc(0,0,i+xWMin*3,0,Math.PI*2);
                ctx.stroke();
            }
            ctx.restore();

            ctx.lineWidth = 2; //电流坐标的粗线
            ctx.save();
            ctx.translate(width/2,height/2);
            for(var j = xWMin * 5; j < xWMin*26; j = j + xWMin*5)
            {
                ctx.beginPath();
                ctx.arc(0,0,j+xWMin*4,0,Math.PI*2);
                ctx.stroke();
            }
            ctx.restore();


            ctx.strokeStyle = "@103458";
            var rMax = xWMin * 44;
            for(var j = 0; j < 360; j += 12.86) //时间坐标的细线
            {
                ctx.save();
                if(Math.floor((j / 12.86) % 4) == 0) {//每4条曲线加一个粗线
                    ctx.lineWidth = 2;
//                    ctx.rotate(Math.PI*90/180);
                }else{
                    ctx.lineWidth = 1;
                }
//                ctx.rotate(0);

                ctx.translate(width/2,height/2);
                ctx.beginPath();
                var startAngle = (180+j-6.5) / 180;   // 内圈长度
                var endAngle = (180+j-38.5) / 180;    // 外圈长度
                var x = rMax * Math.cos(Math.PI * j / 180);
                var y = rMax * Math.sin(Math.PI * j / 180);
                ctx.arc(x, y, rMax, Math.PI * startAngle, Math.PI * endAngle, true);
                ctx.stroke();
                ctx.restore();
            }

            ctx.save();
            ctx.translate(width/2, height/2);
            ctx.font = "22px serif";
            ctx.textAlign = "center";
            ctx.fillText("文10-25井",0,-6);
            ctx.fillText("2022-11-15",0,26);

            //开始画曲线


            ctx.restore();
        }
    }


}

由于webassembly暂时还不支持数据库访问,所以电流数据的获取,我使用了websocket来获取,需要的朋友可以联系我。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值