canvas 画步骤图

文章展示了如何使用HTML5CanvasAPI进行图形绘制,包括arc()方法创建弧形,strokeStyle和fillStyle设置线条和填充颜色,以及fillText()用于绘制文本。代码示例描绘了基于数据数组的多个图形元素。
摘要由CSDN通过智能技术生成

相关属性或方法

  • 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();   // 绘制路线
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值