h5 생산 실적 변화 꺾은선형 차트
이번에는 h5의 성능변화 꺾은선형 차트를 가져오겠습니다. h5 성능변화 꺾은선형 차트 제작 시 주의사항은 무엇인가요?
내부 요소 높이를 동적으로 설정 =>
<!DOCTYPE html><html><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>示例1</title> <style> #title { margin: 2px; font-family: Helvetica, Arial, sans-serif; font-size: 9px; font-weight: bold; line-height: 15px; color: rgb(0, 255, 255); } #demo { width: 74px; height: 30px; background: rgb(0, 255, 255); margin: 2px } span.col { width: 1px; height: 100%; float: left; opacity: 0.9; background: rgb(0, 0, 34); } </style></head><body> <div style=" opacity: 0.9; cursor: pointer; position: absolute; top: 0px;margin: 10px; background: rgb(0, 0, 34);"> <div id="title"></div> <div id="demo"></div> </div> <script> function fillLineChart(id) { this.id = id; this.el = document.getElementById(id); this.value = 0;//当前值 this.width = parseInt(this.el.clientWidth) this.last=this.width-1;//从左往右最后一个span的索引 for (var i = 0; i < this.width; i++) {//初始化span this.el.innerHTML +='<span class="col"></span>'; } this.draw = function (value) {//绘制事件 this.value = value;//记录当前值 for (var i = 0; i <this.last; i++) {//遍历前x-1个,将后一个值赋给前一个 var tmph = this.el.getElementsByTagName("span")[i + 1].style.height;//获取下一个值 this.el.getElementsByTagName("span")[i].style.height = tmph;//赋给当前的 } this.el.getElementsByTagName("span")[this.last].style.height = parseInt(this.el.clientHeight) * (100 - this.value) / 100 + "px";//设置最后span一个高度=span容器的高度x值百分比 } } var demo = new fillLineChart("demo"); var val = 0 setInterval(function () { val = rand(rand(20, 50), 60); document.getElementById('title').innerHTML = `示例(${val})` demo.draw(val); }, 100); function rand(begin, end) { return Math.floor(Math.random() * (end - begin)) + begin; } </script></body></html>
2.By Canvas =>[예]
<!DOCTYPE html><html><head> <meta charset="UTF-8"> <title>示例2</title> <style> #title { margin: 2px; font-family: Helvetica, Arial, sans-serif; font-size: 9px; font-weight: bold; line-height: 15px; color: rgb(0, 255, 255); } #demo { margin: 2px } span.col { width: 1px; height: 100%; float: left; opacity: 0.9; background: rgb(0, 0, 34); } </style></head><body> <div style=" opacity: 0.9; cursor: pointer; position: absolute; top: 0px;margin: 10px; background: rgb(0, 0, 34);"> <div id="title"></div> <canvas id="demo" width="74" height="30"></canvas> </div> <script> function fillLineChart(id) { this.id = id; this.canvas = document.getElementById(id); this.value = 0; this.width = (this.canvas.clientWidth)//获取
바인드 너비
this.height = (this.canvas.clientHeight) //获取高度宽度 this.context = this.canvas.getContext("2d"); this.values = []; this.last = this.width - 1;//最后一个值的索引 for (var i = 0; i < this.width; i++) {//初始化值 this.values.push(this.height); } this.draw = function (value) { this.value = value;//记录当前值 this.context.clearRect(0, 0, this.width, this.height);//清空 this.context.beginPath();//开辟新的绘制路径 this.context.moveTo(0, this.height);//绘制起点 for (var i = 0; i <this.last; i++) { this.values[i] = this.values[i + 1];//移动索引值 this.context.lineTo(i, this.values[i]);//结束位置 } this.values[this.last] = this.height * (100 - value) / 100;//获取最后索引一个值 this.context.lineTo(this.last, this.values[this.last]);//设置最后一个索引位置 this.context.lineTo(i, this.height);//绘制结束 this.context.fillStyle = ' rgb(0, 255, 255)';//填充绘制区域的颜色 this.context.fill();//填充 } } var demo = new fillLineChart("demo"); var val = 0 setInterval(function () { val = rand(rand(20, 50), 60); document.getElementById('title').innerHTML = `示例(${val})` demo.draw(val); }, 100); function rand(begin, end) { return Math.floor(Math.random() * (end - begin)) + begin; } </script></body></html>
3.Canvas 향상=>[예]
<!DOCTYPE html><html><head> <meta charset="UTF-8"> <title>示例3</title> <style> #title {margin: 2px; font-family: Helvetica, Arial, sans-serif; font-size: 9px; font-weight: bold; line-height: 15px; color: rgb(0, 255, 255);} #demo {margin: 2px} span.col { width: 1px; height: 100%; float: left; opacity: 0.9; background: rgb(0, 0, 34);} </style></head><body> <label ><input type="checkbox" onclick="demo.isFull=this.checked" checked/>填充显示</label> <div style=" opacity: 0.9; cursor: pointer; position: absolute; top: 30px;margin: 10px; background: rgb(0, 0, 34);"> <div id="title"></div> <canvas id="demo"></canvas> </div> <script> function lineChart(o) { this.id = o.id; this.canvas = document.getElementById(o.id); this.color = o.color || 'rgb(0, 255, 255)'; this.value = 0; this.isFull = o.isFull || false;//是否填充颜色 this.canvas.width = this.width = o.width || (this.canvas.clientWidth);//获取绑定宽度 this.canvas.height = this.height = o.height || (this.canvas.clientHeight);//获取高度宽度 this.context = this.canvas.getContext("2d"); this.values = []; this.last = this.width - 1;//最后一个值的索引 for (var i = 0; i < this.width; i++) {//初始化值 this.values.push(this.height); } this.draw = function (value) { this.value = value;//记录当前值 this.context.clearRect(0, 0, this.width, this.height);//清空 this.context.beginPath();//开辟新的绘制路径 this.context.moveTo(0, this.isFull ? this.height : this.values[1]);//绘制起点 for (var i = 0; i < this.last; i++) { this.values[i] = this.values[i + 1];//移动索引值 this.context.lineTo(i, this.values[i]);//结束位置 } this.values[this.last] = this.height * (100 - value) / 100;//获取最后索引一个值 this.context.lineTo(this.last, this.values[this.last]);//设置最后一个索引位置 if (this.isFull) { this.context.lineTo(i, this.height);//绘制结束 this.context.fillStyle = this.color;//填充绘制区域的颜色 this.context.fill();//填充 } else { this.context.strokeStyle = this.color; this.context.stroke(); } } } var demo = new lineChart({ id: "demo", width: "74", height: "30", isFull: true, }); var val = 0 setInterval(function () { val = rand(rand(20, 50), 60); document.getElementById('title').innerHTML = `示例(${val})` demo.draw(val); }, 100); function rand(begin, end) { return Math.floor(Math.random() * (end - begin)) + begin; } </script></body> </html>
믿거나 not 이 기사의 사례를 읽은 후에는 방법을 익혔습니다. 더 흥미로운 정보를 보려면 PHP 중국어 웹사이트의 다른 관련 기사를 주목하세요!
관련 읽기:
위 내용은 h5 생산 실적 변화 꺾은선형 차트의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











HTML의 테이블 테두리 안내. 여기에서는 HTML의 테이블 테두리 예제를 사용하여 테이블 테두리를 정의하는 여러 가지 방법을 논의합니다.

HTML 여백-왼쪽 안내. 여기에서는 HTML margin-left에 대한 간략한 개요와 코드 구현과 함께 예제를 논의합니다.

HTML의 Nested Table에 대한 안내입니다. 여기에서는 각 예와 함께 테이블 내에 테이블을 만드는 방법을 설명합니다.

HTML 테이블 레이아웃 안내. 여기에서는 HTML 테이블 레이아웃의 값에 대해 예제 및 출력 n 세부 사항과 함께 논의합니다.

HTML 입력 자리 표시자 안내. 여기서는 코드 및 출력과 함께 HTML 입력 자리 표시자의 예를 논의합니다.

HTML 순서 목록에 대한 안내입니다. 여기서는 HTML Ordered 목록 및 유형에 대한 소개와 각각의 예에 대해서도 설명합니다.

HTML에서 텍스트 이동 안내. 여기서는 Marquee 태그가 구문과 함께 작동하는 방식과 구현할 예제에 대해 소개합니다.

HTML onclick 버튼에 대한 안내입니다. 여기에서는 각각의 소개, 작업, 예제 및 다양한 이벤트의 onclick 이벤트에 대해 설명합니다.
