Canvas-SVG-Echart

概述

canvassvg
画布canvas标签svg标签
语言JS的APIHTML行内属性
过程

定点:确定起点,拐点,终点

连线:连曲线(连圆弧)、连直线

填色:填充颜色

进一步

画文字,画图片

画矩形,画椭圆

SVG

画直线

line(画一条线)

x1:起点横坐标

y1:起点纵坐标

x2:终点横坐标

y2:终点纵坐标

stroke-width:线的厚度

stroke:线的颜色

polygon(画多边形)

points:需要连接的各个点

fill:填充颜色

fill-opacity:填充透明度

stroke-width:边框厚度

stroke:边框颜色

polyline(画多段线)

points:需要连接的各个点

fill:填充颜色

fill-opacity:填充透明度

stroke-width:边框厚度

stroke:边框颜色

path(画路径)......

画曲线

circle(画圆)

cx:圆心横向偏移量

cy:圆心纵向偏移量

r:半径

fill:填充颜色

fill-opacity:填充透明度

stroke-width:边框厚度

stroke:边框颜色

stroke-opacity:边框透明度

ellipse(画椭圆)

cx:圆心横向偏移量

cy:圆心纵向偏移量

rx:横向半径

ry:纵向半径

fill:填充颜色

fill-opacity:填充透明度

stroke-width:边框厚度

stroke:边框颜色

stroke-opacity:边框透明度

rect(画矩形)

  • x:横向偏移量
  • y:纵向偏移量
  • width:宽
  • height:高
  • fill:填充颜色
  • fill-opacity:填充透明度
  • stroke-width:边框厚度
  • stroke:边框颜色
  • stroke-opacity:边框透明度
  • rx:矩形圆角
  • ry:矩形圆角

Canvas

创建对象

<canvas width="500px" height="500px" id="box"></canvas>
const box=document.getElementById('box')
const ctx=box.getContext('2d')

画直线

  • moveTo(x,y):确定新的起点
  • lineTo(x,y):确定拐点
  • beginPath():开启新的线段
  • closePath():闭合路径
  • stroke():从最近的beginPath处,进行连直线
  • lineWidth():线的宽度
  • strokeStyle():线的颜色
  • fill():填色
  • fillStyle():填充的颜色

画线过程

  1. 找到beginPath,找到stroke(),找到其中的moveTo(x,y),lineTo(x,y)
  2. 连接moveTo(x,y)起点、lineTo(x,y)拐点
  3. 连线的宽度由当前ctx的lineWidth决定
  4. 连线的颜色由当前ctx的strokeStyle决定

画圆弧(画曲线)

4781beed1445433f8190dc216d2bb19d.png

  • r:圆的半径
  • x,y:圆心坐标
  • start值是0π:起始点是B(start默认是0π)
  • start值是0.5π:起始点是C;
  • start值是-0.5π:起始点是A
  • stop:确定终点位置(同start)
  • 弧长:start -stop;start=-0.5π,stop=0.5π,弧长为π
  • arc(x,y,r,start,stop):连曲线
  • fill():填色
  • fillStyle():填充的颜色
  • 采用顺时针连线
  • 单位:度(π=360度)

填充矩形

  • fillRect(x,y,width,height):填充出一个矩形
  • x:矩形左上角横坐标
  • y:矩形左上角纵坐标
  • width:矩形宽度
  • heght:矩形高度
  • fillStyle:填充颜色

画、填充文字

  • fillText(text,x,y):填充文字
  • strokeText(text,x,y):画文字

画图片

基本用法

  • drawImage(Img,x,y)
  • drawImage(Img,x,y,width,height)
  • drawImage(Img,cutX,cutY,cutWidth,cuttHeight,x,y,width,height)
  • Img的类型:HTMLImageElement、HTMLCanvasElement、HTMLVideoElement
  • x,y:图片在canvas上的起始位置
  • width,height:图片在canvas上的宽高
  • cutX、cutY:裁剪图片的起始位置
  • cutX、cutY:裁剪图片的宽高

进阶

  • 重复的绘制图片,就可以实现视频效果、游戏动画效果

API

  • canvas.toDataURL(MIME):生成DataURL字符串
  • ctx.clearRect(起始x,起始y,width,height):清空指定区域的画布内容

Base64编码

  • 功能:把二进制数据转换成字符串
  • 编码方式:二进制数据每6位一组,每组转换成对应的Base64字符串
  • DataURL的格式:data:[MIME];base64,[base64字符串]
  • img标签支持格式:DataURL、本地URL、网络URL

abecc31aad2448c28c57c7242c039803.png

Base64编码对应表

还有渐变、组合、变形等,不赘述了

Echarts

创建对象

<div id="main" style="width: 600px;height:400px;"></div>
const myChart = echarts.init(document.getElementById("main"))
const options={……}
myChart.setOption(options)

options

  1. title:一段文字配置
  2. legend:图例配置,展示的数据可以是图表名、单条数据名
  3. xAxis:x坐标轴配置
  4. yAxis:y坐标轴配置
  5. grid:echarts容器与坐标轴的边距
  6. series:图表配置
  7. dataset:图表数据集
  8. radiusAxis:极坐标系-圆半径坐标轴
  9. angleAxis:极坐标系-360°圆弧坐标轴
  10. graphic:可以进行自行绘制
  11. yAxis的第一项默认与series的第一项关联
  12. 距离单位:数字 || 百分比 || "left" || "center" || "right" || "top" || "bottom" || "middle"
  13. rich:文本样式配置
  14. 极坐标系采用的series采用柱状图

yAxis

  • type:坐标轴类型,value(数值轴)、category(类目轴)、time(时间轴)、log(对数轴)
  • name:坐标轴名称
  • nameLocation:坐标轴名称的位置
  • axisLine:坐标轴轴线
  • axisTick:坐标轴刻度线
  • axisLabel:坐标轴每个刻度值的样式
  • splitLine:坐标轴分隔线,即与坐标轴刻度线平齐的那条线
  • position:坐标轴位置 "right" || "left"

series

共性

  • type:图表类型,折线图、柱状图、饼图
  • name:图表名称
  • data:图表数据

pie图

  • left:饼图相对echart容器水平中心线左侧的距离
  • right:饼图相对echart容器水平中心线右侧的距离
  • top:饼图相对echart容器垂直中心线顶部的距离
  • bottom:饼图相对echart垂直中心线容器底部的距离
  • label:每条数据的标签名配置
  • radius: [内圆尺寸,外圆尺寸]

bar图

  • itemStyle:单个柱子的样式

legend

  • data:图表名/饼图数据名的数组
  • icon:图点形状
  • left:图例相对echart容器左侧的距离
  • right:图例相对echart容器右侧的距离
  • top:图例相对echart容器顶部的距离
  • bottom:图例相对echart容器底部的距离
  • orient:布局方向
  • textStyle:文字样式

坐标系

  • 直角坐标系:点的位置由它在水平x 轴和垂直y 轴上的坐标值确定,通常表示为 (x, y)
  • 极坐标系:点的位置由它到原点的距离(极径 r)和该点与参考方向之间的夹角(极角 θ)确定,通常表示为 (r, θ)

HTML5标签引入SVG

svg、jpg、png都是图片的类型

代码

<body>
    <img src="./文件.png" style="..." />
    <img src="./文件.svg" style="..."  />
    <svg t="1687932035351" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="892" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200">
        <path d="M909.312 463.189333L520.533333 658.773333 115.370667 463.189333H39.594667v492.202667c0 36.864 30.037333 67.242667 67.242666 67.242667h811.008c37.205333 0 67.242667-30.037333 67.242667-67.242667V463.189333h-75.776z m0 0" fill="#0086FF" p-id="893">
        </path>
        <path d="M853.333333 0.341333H171.008c-37.205333 0-67.242667 30.037333-67.242667 67.242667v317.44l11.605334 5.461333 167.936 81.237334 237.226666 114.688 227.669334-114.688 161.109333-81.237334 11.264-5.461333v-317.44A67.584 67.584 0 0 0 853.333333 0.341333z m-116.053333 390.144H301.056V301.056H737.28v89.429333z m0-167.594666H301.056V133.12H737.28v89.770667z m0 0" fill="#9BD5F9" p-id="894">
        </path>
    </svg>
</body>

目录 

 41fed546064e4fb5b57edacfbcf877a1.jpeg

效果图 

657f800248f54473a1a7ec54a84bbeb4.jpeg

阿里巴巴帮助引入svg

搜送图标

b683610d2959463f987616e00af98b05.png

添加到购物车

b0990ad8f0f74a59bf835c1f95b8304c.png

添加图标至项目

d1ab9d945c56455f8c3e45f956e81072.png

下载图标到本地

9e6d0c22bf304c7aa3ddc6fffa3d4c55.png

下载的文件目录

1c67ed06861343a1a78c9f8b8f473784.jpeg

unicode使用

  • iconfont.tff、iconfont.woff、iconfont.woff2
  • iconfont.css

15d00be9ab224c73b3fc2cb2718c3f5d.jpeg

font-class使用

  • confont.tff、iconfont.woff、iconfont.woff2
  • iconfont.css

9fdf536f3c3b467cb68cbfbf2476d042.jpeg

symbol使用

  • iconfont.js

b2fae06028c74dd79870b41ace891dfe.jpeg

更新的svg图标 

  1. 点击在线链接生成新的iconfont.css、新的iconfont.css
  2. Font class下有新的iconfont.css
  3. Symbol class下有新的iconfont.js
  4. 新的iconfont.css、iconfont.js替换旧的iconfont.css、iconfont.js

e8236bc1280646708db24a0726842c26.jpeg

5eaa85185a0e4cedae3aba75945aa775.jpeg

​ElementPlus自带图标库

配置

//vite.config.js
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

export default defineConfig({
  plugins: [
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ]
}

使用

用法1
//main.js
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
const app = createApp(App)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

<el-icon :size="20" :color="color"><HomeFilled /></el-icon>
<HomeFilled style="..." />
<el-button icon="HomeFilled" />
<component is="HomeFilled" />


用法2
import {HomeFilled} from '@element-plus/icons-vue'

<el-icon :size="20" :color="color"><HomeFilled /></el-icon>
<HomeFilled style="..." />
<el-button :icon="HomeFilled" />
<component :is="HomeFilled" />

Ant Design自带图标库

5.2.5版本,按需引入图标即可
import {UserOutlined} from "@ant-design/icons"

<UserOutlined />

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

stealPigs-youth

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值