@libregrid/integrated-charts
v1.3.5
Published
Integrated charting for AG Grid Community — part of LibreGrid
Maintainers
Readme
@libregrid/integrated-charts
Create charts from grid ranges and keep them linked to row data. Cross-filter
charts can also filter the grid when users select chart values. Rendering uses
ag-charts-community; commercial-only AG Charts types are not included.
Install
npm install "ag-grid-community@^36.2.0" "ag-charts-community@^14.1.0" @libregrid/integrated-chartsRequires ag-grid-community >=36.1.0 <37 and ag-charts-community as peer
dependencies. @libregrid/cell-selection is installed automatically.
Usage
In a browser TypeScript project, add a grid container before running the code:
<div id="grid" style="height: 400px"></div>
<div id="chart" style="height: 300px"></div>import { ModuleRegistry, AllCommunityModule, createGrid } from 'ag-grid-community';
import { CellSelectionModule } from '@libregrid/cell-selection';
import { IntegratedChartsModule } from '@libregrid/integrated-charts';
ModuleRegistry.registerModules([AllCommunityModule, CellSelectionModule, IntegratedChartsModule]);
const chartContainer = document.querySelector<HTMLElement>('#chart')!;
const api = createGrid(document.querySelector<HTMLElement>('#grid')!, {
columnDefs: [{ field: 'country' }, { field: 'sales' }, { field: 'profit' }],
rowData: [{ country: 'United Kingdom', sales: 120, profit: 40 }],
enableCharts: true,
cellSelection: true,
});
const chart = api.createRangeChart({
chartType: 'groupedColumn',
cellRange: { rowStartIndex: 0, rowEndIndex: 0, columns: ['country', 'sales', 'profit'] },
chartContainer,
});The chart stays linked. Updating the underlying data through
api.applyTransaction(...) updates the chart automatically. Unlink the
chart, save and restore its state, or open its configuration panel through
the grid API:
if (chart) {
api.updateChart({ type: 'rangeChartUpdate', chartId: chart.chartId, unlinkChart: true });
api.openChartToolPanel({ chartId: chart.chartId, panel: 'settings' });
const model = api.getChartModels()?.find((item) => item.chartId === chart.chartId);
chart.destroyChart();
if (model) api.restoreChart(model, chartContainer);
}Cross-filter charts (selecting on the chart filters the grid) use
createCrossFilterChart with the same shape.
API
| Export | Purpose |
| --------------------------- | ------------------------------------------------------------------------------- |
| IntegratedChartsModule | Registers the feature (moduleName: 'IntegratedCharts'). |
| ChartService | Bean backing chart creation, linking, and lifecycle. |
| ChartCrossFilterService | Bean backing cross-filter charts. |
| AgChartsCommunityProvider | The replaceable chart-rendering provider, implemented on ag-charts-community. |
| chartOptionsFor(...) | Translates grid chart config into ag-charts-community options. |
Learn more
- LibreGrid README — full package list and quick start
@libregrid/sparklines— in-cell mini charts, no separate container needed- Chart gaps — what differs from the commercial AG Charts
Angular
Use the same column definitions and grid options with ag-grid-angular.
Register the modules shown above through provideLibreGrid from
@libregrid/angular. See the
Angular setup for a complete component and bootstrap example.
License
MIT — see LICENSE and NOTICE. LibreGrid is an independent project and is not affiliated with, endorsed by, or sponsored by AG Grid Ltd.
