기본 콘텐츠로 건너뛰기

chart.js

Chart.js


특징

 . 깔끔하고 보기좋음.
 . html5 기반. (canvas 사용, IE9 이상)
 . 6가지 타입 제공 (Line, Bar, Radar, Pola area, Pie, Doughnut)
 . 애니메이션 제공
 . http://www.chartjs.org/




Line 타입사용법. 

Data structure
var data = {
 labels : ["January","February","March","April","May","June","July"],
 datasets : [
  {
   fillColor : "rgba(220,220,220,0.5)",
   strokeColor : "rgba(220,220,220,1)",
   pointColor : "rgba(220,220,220,1)",
   pointStrokeColor : "#fff",
   data : [65,59,90,81,56,55,40]
  },
  {
   fillColor : "rgba(151,187,205,0.5)",
   strokeColor : "rgba(151,187,205,1)",
   pointColor : "rgba(151,187,205,1)",
   pointStrokeColor : "#fff",
   data : [28,48,40,19,96,27,100]
  }
 ]
}
.label : x축 라벨
.datasets
 - fillColor : 면적 색
 - strokeColor : 줄 색
 - pointColor : 포인트 색
 - pointStrokeColor : 포인트 테두리 색
 - data : x축에 대응되는 Y값

datasets이 두개인 이유는 한 차트에 두 데이터를 모두 표시하기 위함.

호출 방법 

<canvas id="myChart" width="400" height="400"></canvas>
//Get the context of the canvas element we want to select
var ctx = document.getElementById("myChart").getContext("2d");
var myNewChart = new Chart(ctx).Line(data,option);
option도 Data 처럼 별도로 변수를 만들어 주어야 함.
그런데 default 설정이 괜찮아서 그냥 써도 무방할듯.
Chart(ctx).Line(data); // default 호출

Chart options

var option =  {
    
 //Boolean - If we show the scale above the chart data   
 scaleOverlay : false,
 
 //Boolean - If we want to override with a hard coded scale
 scaleOverride  ....  대략 20가지 정도 되는듯.. }

Browser support

html5 <canvas> 태그를 사용하기 때문에 IE8 이하에서는 제대로 동작하지 않는다. 
excanvas.js 를 별도로 설치
Browser support for the canvas element is available in all modern & major mobile browsers (caniuse.com/canvas).
For IE8 & below, I would recommend using the polyfill ExplorerCanvas - available at https://code.google.com/p/explorercanvas/. It falls back to Internet explorer's format VML when canvas support is not available. Example use:
<head>
 <!--[if lte IE 8]>
  <script src="excanvas.js"></script>
 <![endif]-->
</head>
Usually I would recommend feature detection to choose whether or not to load a polyfill, rather than IE conditional comments, however in this case, VML is a Microsoft proprietary format, so it will only work in IE.
Some important points to note in my experience using ExplorerCanvas as a fallback.

댓글

이 블로그의 인기 게시물

메일서버가 스팸으로 취급받을때

설치한 메일서버를 통해 발송되는 메일이 스팸으로 들어가는 경우가 더러 있다. 이게 한번 들어가기는 쉬운데, 빠져나오기는 드럽게 힘든것 같다... 본인의 경우에는 우선 국내서비스에는 별 무리 없이 들어간다. (naver,daum 등) 그런데 해외메일 그중 Gmail, Hotmail 에는 에누리없이 스팸으로 간주되고 있었다. Gmail같은 경우에는 그래도 스팸함으로 발송은 제대로 되는반면에 Hotmail같은경우에는 아예 수신자체가 안되는 경우도 더러있다.. ㅡ,.ㅡ; 제일 좋은 방법은 Gmail,Hotmail에 전화걸어서 우리 메일서버 IP white Ip로 등록해달라!!! 하면 좋지만, 얘네들은 걸어봤자 자동응답기고, 문의채널은 구글 그룹스 게시판이 전부다.. 본론으로 들어가서. 해외 메일이 차단될 경우 내 매일서버ip가 스팸ip로 등록되 버린 경우일 수 있다. (본인처럼. ㅎ) 이것부터 조회 해보고 싶으면 RBL(real-time blocking List) 체크를 해야 하는데, RBL체크 해주는 사이트는 꽤 많이 있고, 그중 좀 깔끔해 보이는곳 하나 소개. http://www.anti-abuse.org/ 메일서버ip 입력하고 조회해보면 쭈루룩 리스트가 나온다. 그 중 빨간불이 들어온 부분이 메일 서버가 스팸서버가 된 각종 이유들이다.ㅋ 본인의 경우 CBL 때문에 걸렸는데, 내용은 아래와 같다. This IP address is HELO'ing as  "localhost.localdomain"  which violates the relevant standards (specifically: RFC5321). 메일서버 도메인에 별다른 작업을 안해놓아서 "localhost.localdomain" 으로 설정되어있었다. 만약 CBL만 바로 테스트 해보고 싶으면 http://cbl.abusea...

[javascript] 특정시간에만 함수 실행

특정시간에만 팝업을 띄우려면?? 특정시간에만 로그인을 막으려면?? 특정시간에만 할일은 의외로 참 많다. 방법? 딱히 없다. 현재시간 구해서 시작시간, 종료시간 사이에 있을때 시작하는 수밖엔. if ((현재시간 > 시작시간) && (현재시간 < 종료시간)){ .. 팝업노출(); 공사페이지 리다이렉트(); 기타등등(); .. } 자바스크립트로 작성하면 다음과 같다. var startdate = "2014012008" ; var enddate = "2014012418" ; var now = new Date (); //현재시간 year = now. getFullYear (); //현재시간 중 4자리 연도 month = now. getMonth () + 1 ; //현재시간 중 달. 달은 0부터 시작하기 때문에 +1 if ((month + "" ). length < 2 ){ month = "0" + month; //달의 숫자가 1자리면 앞에 0을 붙임. } date = now. getDate (); //현재 시간 중 날짜. if ((date + "" ). length < 2 ){ date = "0" + date; } hour = now. getHours (); //현재 시간 중 시간. if ((hour + "" ). length < 2 ){ hour = "0" + hour; } today = year + "" + month + "" + date + "" + hour; //오늘 날짜 완성. / / 시간비교 i...

(java) 크롬에서 쿠키 삭제 안되는 경우

  java에서 쿠키 삭제하는 방법은 똑같은 이름의 쿠키를 만들고 업데이트 하는 방식이다.  이때 maxAge를 '0' 으로 설정한다.  그래서 아래처럼 코딩한결과  크롬을 제외한 나머지 브라우저에서는 전부 쿠키가 삭제가 되었으나 크롬만 삭제가 되지 않았다.  문제의코드 Cookie cookie = new Cookie(name , null ) ; cookie.setHttpOnly( false ) ; cookie.setMaxAge( 0 ) ; cookie.setPath( "/" ) ; cookie.setDomain( "test.co.kr" ) ; 결론만 얘기하면  Secure 설정을 ture로 추가해서 해결했다.  https, ssl 기반에서만 주고받을 수 있게된다.  public void setSecure ( boolean flag) { secure = flag ; } /** * Returns <code> true </code> if the browser is sending cookies only over a * secure protocol, or <code> false </code> if the browser can send cookies * using any protocol. * * @return <code> true </code> if the browser uses a secure protocol; * otherwise, <code> true </code> * @see #setSecure */ 원인은 이사이트의 쿠키설정중 samesite가 'none' 으로 설정되어있었다.  samesite가 none인 경우에는 반드시 secure 옵션을 같이 넣어줘야 크롬에서 정상동작한다. (chrome 80 버전 업데이트 이슈) 웹서버에서 변경하고 싶으면 nginx.c...