canvas 画步骤图

相关属性或方法

  • arc(x, y, r, sAngle, eAngle, counterclockwise)

arc()方法创建弧/曲线(用于创建圆或部分圆)
提示:如需通过 arc() 来创建圆,请把起始角设置为 0,结束角设置为 2*Math.PI。
提示:请使用 stroke() 或 fill() 方法在画布上绘制实际的弧。
在这里插入图片描述

相关属性

  • strokeStyle(color, gradient, pattern)
    设置或返回用于笔触的颜色、渐变或模式
ctx.strokeStyle = '#0000ff';

相关属性

  • fillStyle(color, gradient, pattern)
    设置或返回用于填充绘画的颜色、渐变或模式
    相关属性
  • fillText(text,x,y,maxWidth)
    fillText()方法在画布上绘制填色的文本。文本的默认颜色是黑色。
    相关属性
  • beginPath() 开始一条路径,或重置当前的路径
  • moveTo(x, y)
    moveTo() 方法把路径移动到画布中的指定点,不创建线条。
    moveTo()相关属性
  • lineTo(x,y)
    lineTo() 方法添加一个新点,然后创建从该点到画布中最后指定点的线条(该方法并不会创建线条)。
    相关属性
  • stroke()
    stroke() 方法会实际地绘制出通过 moveTo() 和 lineTo() 方法定义的路径。默认颜色是黑色。

实现效果图

<canvas @mousemove="handleMove" ref="nodeMap" id="nodeMap" width="600" height="480"></canvas>
let arr = [
   {
        time: '2022-02-03 12:00:00',
        subtitle: '副标题',
        name: '夏利飞'
    },
    {
        time: '2022-02-03 12:00:00',
        subtitle: '副标题',
        name: '夏利飞'
    },
    {
        time: '2022-02-03 12:00:00',
        subtitle: '副标题',
        name: '夏利飞'
    },
    {
        time: '2022-02-03 12:00:00',
        subtitle: '副标题',
        name: '夏利飞'
    },
    {
        time: '2022-02-03 12:00:00',
        subtitle: '副标题',
        name: '夏利飞'
    },
    {
        time: '2022-02-03 12:00:00',
        subtitle: '副标题',
        name: '夏利飞'
    },
    {
        time: '2022-02-03 12:00:00',
        subtitle: '副标题',
        name: '夏利飞'
    },
]
let ctx = this.$refs.nodeMap.getContext("2d");
let x = 21, y = 21; // 圆坐标轴
let line = 140;
arr.forEach((item, index) => {
    ctx.strokeStyle = '#6e6e6e';    // 线颜色
    ctx.fillStyle = '#6e6e6e';  // 文字颜色
    ctx.beginPath();
    ctx.arc(x, y, 20, 0, 2*Math.PI);  // x坐标, y坐标, 半径, 起始角, 结束角
    ctx.font = '20px Arial'
    ctx.fillText(index + 1, x - 5, y + 6);  // 文本, x, y
    ctx.font = '20px Arial';
    ctx.fillText(item.subtitle, x - 20, 60)
    ctx.font = '14px Arial';
    ctx.fillText(item.name, x - 20, 80)
    ctx.fillText(item.time, x - 20, 100)
    ctx.moveTo(x + 20, y);
    ctx.lineTo(x+line, y);
    x = (x + 20 + line);
    ctx.stroke();   // 绘制路线
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Canvas板中插入多张片,可以使用以下步骤: 1. 创建多个Image对象,使用JavaScript代码创建多个Image对象,可以通过new Image()来创建。 2. 加载片,使用Image对象的src属性来设置片的路径,然后监听load事件来确保片已经加载完成。 3. 在Canvas绘制片,使用Canvas上下文对象的drawImage()方法来在Canvas绘制片,可以指定片的位置和大小。 以下是代码示例: ```html <canvas id="canvas" width="500" height="500"></canvas> <script> var canvas = document.getElementById('canvas'); var ctx = canvas.getContext('2d'); var img1 = new Image(); img1.src = 'image1.jpg'; var img2 = new Image(); img2.src = 'image2.jpg'; var img3 = new Image(); img3.src = 'image3.jpg'; var loadedImages = 0; var totalImages = 3; img1.onload = function() { loadedImages++; if (loadedImages === totalImages) { draw(); } } img2.onload = function() { loadedImages++; if (loadedImages === totalImages) { draw(); } } img3.onload = function() { loadedImages++; if (loadedImages === totalImages) { draw(); } } function draw() { ctx.drawImage(img1, 0, 0, canvas.width, canvas.height); ctx.drawImage(img2, 100, 100, 200, 200); ctx.drawImage(img3, 300, 300, 100, 100); } </script> ``` 在上面的示例中,我们首先创建了一个Canvas元素和一个Canvas上下文对象,然后创建了多个Image对象并设置了片路径,接着监听每个片的load事件,每次片加载完成后,将loadedImages加1,当所有片都加载完成后,调用draw()函数,在函数中使用drawImage()方法在Canvas绘制多张片。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值