AG Charts Community Edition
AG Charts is a high-performance, canvas-based JavaScript charting library designed for enterprise applications, offering a comprehensive suite of chart types including line, bar, area, scatter, pie, and many more. It's built without external third-party dependencies for its core functionality, emphasizing performance and customization. The library supports modern web development with full TypeScript types and dedicated framework wrappers for React, Angular, and Vue. Currently, the stable version is 13.2.1, with a rapid release cadence that includes frequent patch and minor updates, and periodic major version releases introducing significant enhancements and breaking changes. Key differentiators include its superior rendering performance, deep customization capabilities via a flexible options API, and a robust feature set suitable for complex data visualizations.
Common errors
-
Cannot read properties of null (reading 'appendChild')
cause The HTML element specified in `container` option either does not exist or has not been rendered to the DOM when `AgCharts.create` is called.fixEnsure the container element exists in your HTML and is available in the DOM before calling `agCharts.AgCharts.create()`. For example, call it within a `DOMContentLoaded` event listener or a React `useEffect` hook. -
TS2345: Argument of type '{...}' is not assignable to parameter of type 'AgChartOptions'. Object literal may only specify known properties, and 'unknownProperty' does not exist in type 'AgChartOptions'.cause You are using an unrecognized or misspelled chart configuration property, or a property that has been removed/renamed in a newer version.fixDouble-check your chart options against the official AG Charts documentation for your specific version. Pay close attention to property casing and structure, especially after major version upgrades (e.g., to v13). -
TypeError: Cannot read properties of undefined (reading 'create')
cause The `AgCharts` object is not correctly imported or is undefined, often due to incorrect CommonJS `require` or ES module `import` syntax.fixEnsure you are using `import * as agCharts from 'ag-charts-community';` and then calling `agCharts.AgCharts.create(...)`. Avoid `import { AgCharts } from 'ag-charts-community';` as it is not the correct export pattern for the main API object.
Warnings
- breaking Many chart options have been renamed or moved within the options structure. Refer to the official migration guide for a complete list of changes.
- breaking The chart's initial configuration can no longer be updated via `AgCharts.update`. This function is now strictly for updating data or specific mutable properties, not for re-configuring the entire chart definition.
- breaking The `highlight-data-points` chart interaction option has been removed, changing how data points are visually emphasized on hover or selection.
- breaking For the mini-map navigator, the `label` and `value` fields within `agCharts.miniMap.navigator` are now mandatory fields.
Install
-
npm install ag-charts-community -
yarn add ag-charts-community -
pnpm add ag-charts-community
Imports
- AgCharts
import { AgCharts } from 'ag-charts-community';import * as agCharts from 'ag-charts-community';
- AgChartOptions
import { AgChartOptions } from 'ag-charts-community';import type { AgChartOptions } from 'ag-charts-community'; - create
import { create } from 'ag-charts-community';import { AgCharts } from 'ag-charts-community'; AgCharts.create({...});
Quickstart
import * as agCharts from 'ag-charts-community';
const options: agCharts.AgChartOptions = {
container: document.getElementById('myChart'),
data: [
{ month: 'Jan', avgTemp: 2, rainfall: 40 },
{ month: 'Feb', avgTemp: 2.3, rainfall: 45 },
{ month: 'Mar', avgTemp: 4.8, rainfall: 50 },
{ month: 'Apr', avgTemp: 7.6, rainfall: 55 },
{ month: 'May', avgTemp: 10.7, rainfall: 60 },
{ month: 'Jun', avgTemp: 13.9, rainfall: 65 },
{ month: 'Jul', avgTemp: 16.2, rainfall: 70 },
{ month: 'Aug', avgTemp: 15.9, rainfall: 75 },
{ month: 'Sep', avgTemp: 13.3, rainfall: 80 },
{ month: 'Oct', avgTemp: 9.3, rainfall: 70 },
{ month: 'Nov', avgTemp: 5.7, rainfall: 60 },
{ month: 'Dec', avgTemp: 3.1, rainfall: 50 }
],
series: [
{
type: 'line',
xKey: 'month',
yKey: 'avgTemp',
yName: 'Avg Temperature (°C)'
},
{
type: 'bar',
xKey: 'month',
yKey: 'rainfall',
yName: 'Rainfall (mm)'
}
],
axes: [
{
type: 'category',
position: 'bottom',
title: { text: 'Month' }
},
{
type: 'number',
position: 'left',
keys: ['avgTemp'],
title: { text: 'Temperature (°C)' }
},
{
type: 'number',
position: 'right',
keys: ['rainfall'],
title: { text: 'Rainfall (mm)' },
grid: { enabled: false }
}
],
title: {
text: 'Monthly Weather Data'
},
subtitle: {
text: 'London, 2023'
}
};
// Ensure a container element exists for the chart
if (!document.getElementById('myChart')) {
const chartDiv = document.createElement('div');
chartDiv.id = 'myChart';
chartDiv.style.height = '400px';
chartDiv.style.width = '600px';
document.body.appendChild(chartDiv);
}
agCharts.AgCharts.create(options);