> ## Documentation Index
> Fetch the complete documentation index at: https://docs.reducto.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Charts

`sheet.charts.add(type, source, seriesBy)` makes a chart over a block of cells, as Insert Chart does in Microsoft Excel. Labels in the first row and column become series names and categories. The chart reads its cells, so it follows later edits.

```ts theme={null}
import { ExcelWorkbook } from "@reductoai/xlsx/node";

const book = ExcelWorkbook.create();
const sheet = book.worksheets.getActiveWorksheet();
sheet.getRange("A1:C4").values = [
  ["Region", "Q1", "Q2"],
  ["North", 10, 12],
  ["South", 8, 15],
  ["West", 11, 9],
];
const chart = sheet.charts.add("ColumnClustered", sheet.getRange("A1:C4"), "Auto");
chart.title.text = "Sales by region";
chart.legend.position = "Bottom";
chart.setPosition("E2", "L18");
await book.save("chart.xlsx");
await book.toPng({ range: "Sheet1!A1:L18" });
```

`type` is an `Excel.ChartType` name: `"ColumnClustered"`, `"BarClustered"`, `"Line"`, `"Pie"`, `"XYScatter"` and so on. `seriesBy` is `"Auto"`, `"Rows"` or `"Columns"`.

## Size and series

```ts theme={null}
import { ExcelWorkbook } from "@reductoai/xlsx/officejs";

const book = ExcelWorkbook.fromBytes(bytes);
const sheet = book.worksheets.getItem("Sheet1");
const chart = sheet.charts.add("Line", "A1:C4");
chart.top = 200; // points
chart.left = 300;
chart.width = 480;
chart.height = 288;
chart.series.getItemAt(0).name = "First quarter";
console.log(chart.chartType, chart.series.count);
```
