canvas 连线曲线图
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no">
<meta content="telephone=no" name="format-detection" />
<title></title>
<script src="js/jquery-3.3.0.js"></script>
<style>
*{
margin: 0px;
padding: 0px;
}
.tab{
width:900px;
margin: 0 auto;
position: relative;
}
.active{display: inline-block;
width: 20px;
height: 20px;
background-color: red;
text-align: center;
line-height: 20px;
color: #fff;
border-radius: 50%;
}
td{
text-align: center;
}
</style>
<script>
$(function () {
var tbody= $("#tbody");
var str='';
var arr=[3,2,5,4,7,9,1,6,8,3,2,5,4,7,9,7,8,8];
var span=function (le,le1) {
if(le==le1){
return '<span class="active">'+le1+'</span>';
}else {
return le1;
}
}
for (let i=0;i<arr.length;i++) {
str+='<tr id="'+i+'">' +
'<td>'+span(arr[i],0)+'</td>' +
'<td>'+span(arr[i],1)+'</td>' +
'<td>'+span(arr[i],2)+'</td>' +
'<td>'+span(arr[i],3)+'</td>' +
'<td>'+span(arr[i],4)+'</td>' +
'<td>'+span(arr[i],5)+'</td>' +
'<td>'+span(arr[i],6)+'</td>' +
'<td>'+span(arr[i],7)+'</td>' +
'<td>'+span(arr[i],8)+'</td>' +
'<td>'+span(arr[i],9)+'</td>' +
'</tr>';
}
var s= $(str).appendTo(tbody);
$(".active",s).hover(function () {
var setoff=$(this).offset();
console.log(setoff.top,setoff.left)
}); var arr=[];
$.each($(".active",tbody),function () {
var setoff=$(this).offset();
var jo={"top":setoff.top,"left":setoff.left,id:$(this).parent().parent().attr("id"),w:$(this).width(),h:$(this).height()};
arr.push(jo);
}); for(let a=arr.length-1;a>0;a--){
var c=document.createElement("canvas");
var wLeft=tbody.offset().left;
var wTop=tbody.offset().top;
var st=arr[a];
var pr=arr[a-1];
var cTop=Math.min(st.top,pr.top);
var cLeft=Math.min(st.left,pr.left);
var cw,cuLeft,ch,cuTop,mToLeft,mToTop,liToLeft,liToTop;
var activeH=st.h/2;
if(st.left<pr.left){
cw= pr.left-st.left-st.h;
cuLeft= st.left-wLeft+st.h;
ch=st.top-pr.top;
cuTop=pr.top-wTop+activeH;
mToLeft=pr.left-cLeft;
mToTop=pr.top-cTop;
liToLeft=st.left-cLeft;
liToTop=st.top-cTop;
}else if(st.left==pr.left){
cw= st.w;
cuLeft=st.left-wLeft;
ch=(st.top-pr.top)/2+5;
cuTop=pr.top-wTop+st.h;
mToLeft=cw/2;
mToTop=pr.top-cTop;
liToLeft=cw/2;
liToTop=st.top-cTop;
}else{
cw=st.left-pr.left-st.h;
cuLeft=st.left-wLeft-cw;
ch=st.top-pr.top;
cuTop=pr.top-wTop+activeH;
mToLeft=pr.left-cLeft;
mToTop=pr.top-cTop;
liToLeft=st.left-cLeft;
liToTop=st.top-cTop;
}
c.style.position='absolute';
c.style.top=cuTop+"px";
c.style.left=cuLeft+"px";
c.width=cw;
c.height=ch;
c.id=arr[a].id;
let cx=c.getContext("2d");
cx.strokeStyle="red";
cx.moveTo(mToLeft,mToTop);
cx.lineTo(liToLeft,liToTop);
cx.stroke();
$(c).appendTo(tbody);
} }); </script>
</head>
<body>
<div class="tab">
<table width="100%" cellpadding="0" cellspacing="0" >
<thead>
<tr></tr>
</thead>
<tbody id="tbody"></tbody>
</table>
</div>
</body> </html>

canvas 连线曲线图的更多相关文章
- canvas 连线曲线图封装
$.fn.hChart=function (opt) { var setting=$.extend({ className:'', data:[] },opt); var tbody=this; va ...
- 兼容IE浏览器的canvas画线和圆圈
1.新建test.html文件,代码如下: <!DOCTYPE html><html><head> <meta charset="utf-8& ...
- canvas 画线
一.canvas是基于状态的绘图环境 1.canvas是基于状态的绘制 context.moveTo(100,100); context.lineTo(700,700); context.lineWi ...
- canvas绘制线和矩形
###canvas绘制矩形 HTML中的元素canvas只支持一种原生的图形绘制:矩形.所有其他的图形的绘制都至少需要生成一条路径 1.绘制矩形 canvas提供了三种方法绘制矩形: ----> ...
- canvas连线特效
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- canvas 添加线和删除线 及获取相关位置信息源码
其他相关链接: https://github.com/lusase/lineDrawer.git https://www.jb51.net/css/359062.html https://www.jb ...
- HTML5之Canvas绘图实例——曲线图
实现正弦.余弦和正切函数画图(如下图):调试环境:Firefox
- 利用Canvas进行绘制XY坐标系
首先来一发图 绘制XY的坐标主要是利用Canvas setLeft和setBottom功能(Canvas内置坐标的功能) 1.首先WPF中的坐标系都是从左到右,从上到下的 即左上角位置(0,0)点,所 ...
- HTML5 Canvas中实现绘制一个像素宽的细线
正统的HTML5 Canvas中如下代码 ctx.lineWidth = 1; ctx.beginPath(); ctx.moveTo(10, 100); ctx.lineTo(300,100); c ...
随机推荐
- (4)pyspark---dataframe清理
1.交叉表(crosstab): pandas中也有,常和pivot_table比较. 查看家庭ID与评分的交叉表: 2.处理缺失值:fillna withColumn:新增一列数据 cast : 用 ...
- JS数据分组[JSON]
JS 数据分组 var arr = [{ "id": "1001", "name": "值1", "value ...
- python_形参、实参
#参数:形参.实参'''def display_message(title): print("My favourite book is %s" %title) #return 0 ...
- 使用InstelliJ IDEA创建Spring MVC应用程序
环境版本 Windows 8.1 IDE:InstelliJ IDEA 13 Spring:Spring 4.1.1 & Spring MVC 4.1.1 WebLogic 10. ...
- Visual Studio 2015 改变窗体图标 & 任意位置打开窗体 & 禁止鼠标改动窗体大小
1.改变窗体图标 先把图标放到项目文件夹中,然后点击窗体属性的ICON添加即可. 参考:https://www.cnblogs.com/yangxuli/p/8075484.html?tdsource ...
- javaScript将string转换成array,并将汉字按汉语拼音排序方法
亲测,代码如下: var str = '中华人民共和国民主富强': var arr = str.split("");//字符串装换数组方法一 //arr = str.replace ...
- WinServer-IIS-Dynamic IP Restrictions
动态IP限制 来自为知笔记(Wiz)
- HDU——T The King’s Problem
http://acm.hdu.edu.cn/showproblem.php?pid=3861 Time Limit: 2000/1000 MS (Java/Others) Memory Limi ...
- Bootstrap组件之页头、缩略图
.page-header--指定div元素包裹页头组件. <div class="page-header"> <h1>小镇菇凉<small> 2 ...
- Android动态加载字节码
概述 面对App业务逻辑的频繁变更,如果每一次改变都对App进行一次升级,会降低App的用户体验,那么App进行模块化升级(这里与增量升级是不同的)是很好的解决方案,让用户在完全无感觉的情况下改变Ap ...