Class DataTableBuilder
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
DataTableBuilder
DataTable 객체의 빌더입니다. 데이터 표를 빌드하는 작업은 먼저 열을 지정한 다음 행을 하나씩 추가하는 것으로 구성됩니다. 예:
const data = Charts.newDataTable()
.addColumn(Charts.ColumnType.STRING, 'Month')
.addColumn(Charts.ColumnType.NUMBER, 'In Store')
.addColumn(Charts.ColumnType.NUMBER, 'Online')
.addRow(['January', 10, 1])
.addRow(['February', 12, 1])
.addRow(['March', 20, 2])
.addRow(['April', 25, 3])
.addRow(['May', 30, 4])
.build();
자세한 문서
addColumn(type, label)
데이터 표에 열을 추가합니다. 열은 0부터 n까지 추가됩니다.
첫 번째 열은 차트에서 라벨에 자주 사용됩니다 (예: 선 차트의 X축 라벨 또는 원형 차트의 슬라이스 라벨). 다른 열은 데이터에 사용되는 경우가 많으므로 숫자 값이 필요한 경우가 많습니다.
매개변수
이름 | 유형 | 설명 |
type | ColumnType | 열의 데이터 유형 (숫자, 문자열, 날짜) |
label | String | 열 라벨 (차트 범례에 사용됨) |
리턴
DataTableBuilder
: 체이닝을 위한 이 빌더
addRow(values)
데이터 표에 행을 추가합니다.
매개변수
이름 | 유형 | 설명 |
values | Object[] | 열이 입력된 순서와 동일하게 지정된 행의 값입니다. |
리턴
DataTableBuilder
: 체이닝을 위한 이 빌더
build()
데이터 표를 빌드하고 반환합니다.
리턴
DataTable
: 데이터 표
생성 값
Error
: 데이터 테이블이 비어 있거나 형식이 잘못된 경우
setValue(row, column, value)
표에 특정 값을 설정합니다.
데이터 표에 열을 추가하기 전에 값을 설정할 수 있습니다. 그러나 열이 추가되지 않으면 값은 무시됩니다.
모든 열 값을 채울 필요는 없습니다. 누락된 항목은 null
로 간주됩니다.
매개변수
이름 | 유형 | 설명 |
row | Integer | 행 색인 (첫 번째 행의 색인은 0) |
column | Integer | 열 색인 (첫 번째 열의 색인은 0) |
value | Object | 표 셀의 값 (열에 적합한 유형이어야 함) |
리턴
DataTableBuilder
: 체이닝을 위한 이 빌더
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-07-26(UTC)
[null,null,["최종 업데이트: 2025-07-26(UTC)"],[[["\u003cp\u003eDataTableBuilder facilitates the creation of DataTable objects by defining columns and adding rows sequentially.\u003c/p\u003e\n"],["\u003cp\u003eColumns are defined using \u003ccode\u003eaddColumn\u003c/code\u003e with specified data type and label, and rows are added using \u003ccode\u003eaddRow\u003c/code\u003e with corresponding values.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003ebuild\u003c/code\u003e method finalizes the DataTable construction and returns the resulting object.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003esetValue\u003c/code\u003e allows modification of individual cell values within the table by specifying row, column, and the new value.\u003c/p\u003e\n"],["\u003cp\u003eDataTableBuilder uses a chaining pattern, where method calls can be linked for streamlined table construction.\u003c/p\u003e\n"]]],[],null,["# Class DataTableBuilder\n\nDataTableBuilder\n\nBuilder of DataTable objects. Building a data table consists of first specifying its columns, and\nthen adding its rows, one at a time. Example:\n\n```javascript\nconst data = Charts.newDataTable()\n .addColumn(Charts.ColumnType.STRING, 'Month')\n .addColumn(Charts.ColumnType.NUMBER, 'In Store')\n .addColumn(Charts.ColumnType.NUMBER, 'Online')\n .addRow(['January', 10, 1])\n .addRow(['February', 12, 1])\n .addRow(['March', 20, 2])\n .addRow(['April', 25, 3])\n .addRow(['May', 30, 4])\n .build();\n``` \n\n### Methods\n\n| Method | Return type | Brief description |\n|-------------------------------------------------------------------|-------------------------------------------------------|-------------------------------------|\n| [addColumn(type, label)](#addColumn(ColumnType,String)) | [DataTableBuilder](#) | Adds a column to the data table. |\n| [addRow(values)](#addRow(Object)) | [DataTableBuilder](#) | Adds a row to the data table. |\n| [build()](#build()) | [DataTable](/apps-script/reference/charts/data-table) | Builds and returns a data table. |\n| [setValue(row, column, value)](#setValue(Integer,Integer,Object)) | [DataTableBuilder](#) | Sets a specific value in the table. |\n\nDetailed documentation\n----------------------\n\n### `add``Column(type, label)`\n\nAdds a column to the data table. Columns will be added from 0 to n.\n\nThe first column is often used by charts for labels (for instance, X-axis labels on line\ncharts, or slice labels in pie charts). The other columns are often used for data and therefore\noften require numeric values.\n\n#### Parameters\n\n| Name | Type | Description |\n|---------|---------------------------------------------------------|------------------------------------------------------|\n| `type` | [ColumnType](/apps-script/reference/charts/column-type) | type of data in the column (number, string, or date) |\n| `label` | `String` | label of the column (it's used for chart legends). |\n\n#### Return\n\n\n[DataTableBuilder](#) --- this builder, for chaining.\n\n*** ** * ** ***\n\n### `add``Row(values)`\n\nAdds a row to the data table.\n\n#### Parameters\n\n| Name | Type | Description |\n|----------|------------|-------------------------------------------------------------------------------|\n| `values` | `Object[]` | values for the row, specified in the same order that the columns are entered. |\n\n#### Return\n\n\n[DataTableBuilder](#) --- this builder, for chaining.\n\n*** ** * ** ***\n\n### `build()`\n\nBuilds and returns a data table.\n\n#### Return\n\n\n[DataTable](/apps-script/reference/charts/data-table) --- the data table\n\n#### Throws\n\n\n[`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) --- if the data table is empty or otherwise malformed\n\n*** ** * ** ***\n\n### `set``Value(row, column, value)`\n\nSets a specific value in the table.\n\nYou may set a value before adding the column to the data table. However, unless the column\nis added at some point, the value will be ignored.\n\nNot all column values need to be filled in. Those missing will be considered `null`.\n\n#### Parameters\n\n| Name | Type | Description |\n|----------|-----------|--------------------------------------------------------------------------|\n| `row` | `Integer` | the row index (the first row has index 0) |\n| `column` | `Integer` | the column index (the first column has index 0) |\n| `value` | `Object` | the value of the table cell (should have the right type for the column). |\n\n#### Return\n\n\n[DataTableBuilder](#) --- this builder, for chaining"]]