구글 차트

간단한 꺾은선형 차트에서 복잡한 계층적 트리 맵에 이르기까지 Google 차트 갤러리는 바로 사용할 수 있는 다양한 차트 유형을 제공합니다.

  • 분산형 차트
  • 라인 차트
  • 막대형 / 기둥형 차트
  • 영역 차트
  • 파이 차트
  • 도넛 차트
  • 조직도
  • 지도 / 지리 차트

Google 차트를 사용하는 방법?

웹 페이지에서 Google 차트를 사용하려면 차트 로더에 대한 링크를 추가하십시오 .

<script
src="https://www.gstatic.com/charts/loader.js">
</script>

Google 차트는 사용하기 쉽습니다.

차트를 표시하려면 <div> 요소를 추가하기만 하면 됩니다.

<div id="myChart" style="max-width:700px; height:400px"></div>

<div> 요소에는 고유한 ID가 있어야 합니다.

그런 다음 Google 그래프 API를 로드합니다.

  1. Visualization API 및 corechart 패키지 로드
  2. API가 로드될 때 호출할 콜백 함수 설정
1 google.charts.load('current',{packages:['corechart']});

2 google.charts.setOnLoadCallback(drawChart);

그게 다야!


선 그래프

House Prices vs. Size60801001201400.02.55.07.510.012.515.0Square MetersPrice in Millions
가격크기
507
608
708
809
909
1009
11010
12011
13014
14014
15015

소스 코드

function drawChart() {
// Set Data
var data = google.visualization.arrayToDataTable([
  ['Price', 'Size'],
  [50,7],[60,8],[70,8],[80,9],[90,9],[100,9],
  [110,10],[120,11],[130,14],[140,14],[150,15]
  ]);
// Set Options
var options = {
  title: 'House Prices vs Size',
  hAxis: {title: 'Square Meters'},
  vAxis: {title: 'Price in Millions'},
  legend: 'none'
};
// Draw Chart
var chart = new google.visualization.LineChart(document.getElementById('myChart'));
chart.draw(data, options);
}


산점도

동일한 데이터 를 산점도 에 표시하려면 google.visualization을 LineChart로 변경합니다.

var chart = new google.visualization.LineChart(document.getElementById('myChart'));

House Prices vs. Size0501001500.02.55.07.510.012.515.0Square MetersPrice in Millions
가격크기
507
608
708
809
909
1009
11010
12011
13014
14014
15015

막대 차트

World Wide Wine ProductionMhl0204060ItalyFranceSpainUSAArgentina
콘트리
이탈리아55
프랑스49
스페인44
미국24
아르헨티나15

소스 코드

function drawChart() {

var data = google.visualization.arrayToDataTable([
  ['Contry', 'Mhl'],
  ['Italy', 55],
  ['France', 49],
  ['Spain', 44],
  ['USA', 24],
  ['Argentina', 15]
]);

var options = {
  title: 'World Wide Wine Production'
};

var chart = new google.visualization.BarChart(document.getElementById('myChart'));
chart.draw(data, options);

}


파이 차트

막대 차트를 원형 차트 로 변환하려면

google.visualization 으로 바꾸 세요. BarChart

:

google.visualization. 파이 차트

var chart = new google.visualization.PieChart(document.getElementById('myChart'));

World Wide Wine ProductionItalyFranceSpainUSAArgentina29.4%8%12.8%23.5%26.2%
콘트리
이탈리아55
프랑스49
스페인44
미국24
아르헨티나15

3D 파이

파이를 3D로 표시하려면 옵션 에 is3D: true 를 추가하기만 하면 됩니다.

var options = {
  title: 'World Wide Wine Production',
  is3D: true
};

World Wide Wine ProductionItalyFranceSpainUSAArgentina29.4%8%12.8%23.5%26.2%
콘트리
이탈리아55
프랑스49
스페인44
미국24
아르헨티나15