我想我会用Raphaël 来做这样的事情。它易于使用并支持所有主流浏览器。动画线条绘制可能有点麻烦,因为您必须将每个步骤生成为单独的路径,但这应该不难。
这是一个非常简单的例子
var points = [
{ x: 0, y: 0, t: 0 },
{ x: 100, y: 230, t: 1520 },
{ x: 210, y: 290, t: 3850 },
{ x: 150, y: 200, t: 5060 },
];
var paths = [];
// build paths
points.forEach(function (p, idx) {
if (idx === 0) {
paths.push('M ' + p.x + ' ' + p.y);
} else {
paths.push(paths[idx - 1] + ' L ' + p.x + ' ' + p.y);
}
});
var paper = Raphael(10, 10, 300, 300);
var line = paper.path(paths[0]);
var next = 1;
function animate() {
if (paths[next]) {
duration = points[next].t - points[next - 1].t
line.animate({ path: paths[next] }, duration, 'linear', animate);
next++;
}
}
animate();
这是一个小提琴,您可以在其中看到它的实际效果:http: //jsfiddle.net/toxicsyntax/FLPdr/ UPDATE
这是使用上述代码的完整 HTML 页面。它仍然是一个简化的示例,但您应该能够按照自己的方式工作。
<!DOCTYPE html>
<html>
<head>
<title>Raphael Play</title>
<script type="text/javascript" src="https://raw.github.com/DmitryBaranovskiy/raphael/master/raphael-min.js"></script>
<script type="text/javascript">
function drawLine(points) {
var paths = ['M ' + points[0].x + ' ' + points[0].y];
// build paths
for (var i = 1; i < points.length; i++) {
var p = points[i];
paths.push(paths[i - 1] + ' L ' + p.x + ' ' + p.y);
}
// get drawing surface
var paper = new Raphael(document.getElementById('canvas_container'), 500, 500);
// draw line
var line = paper.path(paths[0]);
var next = 1;
function animate() {
if (paths[next]) {
duration = points[next].t - points[next - 1].t
line.animate({ path: paths[next] }, duration, 'linear', animate);
next++;
}
}
animate();
}
</script>
<style type="text/css">
#canvas_container {
width: 500px;
border: 1px solid #aaa;
}
</style>
</head>
<body>
<div id="canvas_container"></div>
<script type="text/javascript">
window.onload = function () {
// the points here should be generated by your ASP.NET application
drawLine([
// the points here should be generated by your ASP.NET application
{ x: 0, y: 0, t: 0 },
{ x: 100, y: 230, t: 1520 },
{ x: 210, y: 290, t: 3850 },
{ x: 150, y: 200, t: 5060 },
]);
}
</script>
</body>
</html>
The points are at the end of the HTML page, and in your application you could generate those from your model.