两部分内容,来自两文章。
http://www.dnbcw.com/biancheng/javascript/ksat167485.html
http://www.iwms.net/n426c19.aspx
一、DIV法
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
#container { width: 200px; height: 100px; border: 1px solid red; position: relative;}
#chart { position: absolute; height: 200px}
</style>
</head>
<body>
<div id="container">
<div id="chart"></div>
</div>
<script>
void function() {
var arr = [], T$ = function(id) { return document.getElementById(id); },
fx = function(t,b,c,d){ return c*t/d + b; }, i = 0;
for ( ; i < 200; i++) {
arr.push('<div style="width:1px;height:1px;font-size:0;background-color:#FF0066;position:absolute;left:'+(i - 1)+'px;top:'+(Math.ceil(fx(i, 0, 100, 200)))+'px"><\/div>');
}
T$('chart').innerHTML = arr.join('');
}();
</script>
</body>
</html>
二、VML法
v:line父元素的padding会影响from及to的坐标。