web chart - 실시간 차트


https://www.chartjs.org 

https://c3js.org/ 



실시간차트



axㅁㅁㅁㅁ

<!DOCTYPE html> <html lang="ko"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>실시간 인터랙티브 차트</title> <script src="https://d3js.org/d3.v5.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/c3/0.7.20/c3.min.js"></script> <link href="https://cdnjs.cloudflare.com/ajax/libs/c3/0.7.20/c3.min.css" rel="stylesheet"> <style> #chart { width: 100%; height: 500px; } .annotation { position: absolute; background: white; border: 1px solid black; padding: 5px; display: none; } .selection { fill: rgba(0, 0, 255, 0.1); stroke: blue; } </style> </head> <body> <div id="chart"></div> <div id="annotation" class="annotation"> <textarea id="annotationText" rows="3" cols="30"></textarea> <button onclick="saveAnnotation()">저장</button> </div> <script> let chart; let data = []; let annotations = []; let selectedRange = null; function initChart() { chart = c3.generate({ bindto: '#chart', data: { columns: [ ['data', ...data] ] }, axis: { y: { padding: { top: 100, bottom: 100 } } }, zoom: { enabled: true }, subchart: { show: true } }); d3.select('#chart svg') .call(d3.drag().on("drag", dragged)) .on("wheel", zoomed) .on("click", clicked); d3.select('#chart svg') .append("rect") .attr("class", "selection") .style("display", "none"); } function updateChart() { const newValue = Math.random() * 100; data.push(newValue); if (data.length > 100) data.shift(); chart.load({ columns: [ ['data', ...data] ] }); updateAnnotations(); setTimeout(updateChart, 1000); } function dragged(event) { const dx = d3.event.dx; const range = chart.x.range(); const domainDiff = chart.x.invert(range[1]) - chart.x.invert(range[0]); const domainDx = (domainDiff / (range[1] - range[0])) * dx; chart.zoom.translate([chart.zoom.translate()[0] - domainDx, 0]); chart.zoom.update(); } function zoomed(event) { const direction = d3.event.deltaY < 0 ? 'in' : 'out'; const factor = direction === 'in' ? 1.1 : 0.9; chart.zoom.scale(chart.zoom.scale() * factor); chart.zoom.update(); } function clicked(event) { const [x, y] = d3.mouse(this); const xValue = chart.x.invert(x); const yValue = chart.y.invert(y); const annotation = document.getElementById('annotation'); annotation.style.left = `${x}px`; annotation.style.top = `${y}px`; annotation.style.display = 'block'; selectedRange = { x: xValue, y: yValue }; } function saveAnnotation() { const text = document.getElementById('annotationText').value; annotations.push({ ...selectedRange, text }); document.getElementById('annotation').style.display = 'none'; document.getElementById('annotationText').value = ''; updateAnnotations(); } function updateAnnotations() { d3.selectAll('.annotation-point').remove(); d3.selectAll('.annotation-tooltip').remove(); annotations.forEach(ann => { const x = chart.x(ann.x); const y = chart.y(ann.y); d3.select('#chart svg') .append('circle') .attr('class', 'annotation-point') .attr('cx', x) .attr('cy', y) .attr('r', 5) .attr('fill', 'red'); d3.select('#chart svg') .append('text') .attr('class', 'annotation-tooltip') .attr('x', x + 10) .attr('y', y - 10) .text(ann.text); }); } initChart(); updateChart(); </script> </body> </html> 
0
0
이 글을 페이스북으로 퍼가기 이 글을 트위터로 퍼가기 이 글을 카카오스토리로 퍼가기 이 글을 밴드로 퍼가기

HTML/CSS/기타

번호 제목 글쓴이 날짜 조회수
29 자주 사용하는 비주얼 스튜디오 코드(Visual Studio Code, VSC, vscode) 단축키 정리 관리자 09-14 5,383
28 div 2개 나란히 정렬하는 방법 관리자 09-09 4,945
27 HTML, CSS - 헤더컬럼 고정형 table 구성하기 관리자 09-06 4,500
26 Drag and Drop File Upload 관리자 09-03 3,085
25 rowspan으로 합친 table에서 룰오버 관리자 08-23 2,589
24 스마트에디터 입력 용량 체크 관리자 07-06 1,969
23 자바스크립트 정규표현식 모음 관리자 07-03 1,253
22 [Javascript] 쓰레드(웹 워커-Web worker)를 사용하는 방법 관리자 04-13 1,126
21 구글 차트 관리자 04-12 1,700
20 Camera API 관리자 04-07 852
19 전화번호 자동 정규식 처리 관리자 04-06 903
18 picocss 관리자 04-03 854
17 CSS 폰트 적용하기 관리자 03-15 754
16 JQuery html2canvas div 이미지 저장 (div 영역 이미지 캡쳐) 관리자 03-15 2,472
15 [#. CSS] 이미지 위에 텍스트, 글자 올리기 text on image 관리자 03-15 2,549
14 다음 지도 api 주소을 좌표 구하고 여러개 마커 제어하기 관리자 03-08 1,140
13 jquery upload 관리자 02-27 686
12 QR코드 활용에 관하여… 관리자 02-08 918
11 비밀번호 정규식 모음 관리자 11-21 832
10 JQuery 노드찾기 관리자 11-12 847