canvas画布如何画图案例

时间:2023-12-26 08:13:01

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>基础折线图</title>
<style>::-webkit-scrollbar{display:none;}html,body{overflow:hidden;}</style>
</head>
<body>
<div style="width:600px; height:500px; margin: 0 auto;">
<canvas id="mountNode" width="600" height="400" ></canvas>
</div>
<script>
/*Fixing iframe window.innerHeight 0 issue in Safari*/
document.body.clientHeight;
</script>
<script src="f2.js"></script>
<script>
F2.Global.pixelRatio = window.devicePixelRatio;
const data = [
{ time: '2016-08-08 00:00:00', tem: 10 },
{ time: '2016-08-08 00:10:00', tem: 22 },
{ time: '2016-08-08 00:30:00', tem: 20 },
{ time: '2016-08-09 00:35:00', tem: 26 },
{ time: '2016-08-09 01:00:00', tem: 20 },
{ time: '2016-08-09 01:20:00', tem: 26 },
{ time: '2016-08-10 01:40:00', tem: 28 },
{ time: '2016-08-10 02:00:00', tem: 20 },
{ time: '2016-08-10 02:20:00', tem: 28 }
];

const chart = new F2.Chart({
id: 'mountNode'
});

const defs = {
time: {
type: 'timeCat',
mask: 'MM/DD',
tickCount: 3,
range: [ 0, 1 ]
},
tem: {
tickCount: 5,
min: 0
}
};
// 配置刻度文字大小,供PC端显示用(移动端可以使用默认值20px)
chart.axis('tem', {
label: {
fontSize: 14
}
});
chart.axis('time', {
label: {
fontSize: 14
}
});
chart.source(data, defs);
chart.line().position('time*tem');
chart.render();
</script>
</body>
</html>