ngx-charts Documentation
repository·master·Indexed 26 days ago
https://github.com/swimlane/ngx-chartsA declarative charting framework for Angular that uses Angular for SVG rendering and animation, while utilizing D3 for mathematical calculations and scales. It supports a wide variety of chart types including Bar, Line, Area, Pie, Bubble, Donut, Gauge, Heatmap, Treemap, Number Cards, and Sankey Diagrams. The library is compatible with AoT and Universal, offering CSS-based styling and a set of building blocks (Legends, Axes, Shapes) for constructing custom visualizations.
What's inside ngx-charts
- ngx-charts is a declarative charting framework for Angular. Unlike libraries that simply wrap D3, ngx-charts uses Angular to render and animate SVG elements, leveraging Angular's binding and speed. It utilizes D3 specifically for mathematical functions, scales, axes, and shape generators. Because Angular handles the rendering, the library is compatible with Angular features like AoT (Ahead-of-Time compilation) and Universal.
Overview of ngx-charts features and chart types
masterngx-charts is a declarative charting framework for Angular that uses Angular to render and animate SVG elements while leveraging D3 for mathematical functions, scales, axes, and shape generators. This approach enables support for Angular features like AoT and SSR.
Supported Chart Types
- Bar Charts: Horizontal & Vertical (Standard, Grouped, Stacked, Normalized)
- Line Charts
- Area Charts: Standard, Stacked, Normalized
- Pie Charts: Explodable, Grid, Custom legends
- Bubble Charts
- Donut Charts
- Gauge Charts: Linear & Radial
- Heatmap
- Treemap
- Number Cards
- Sankey Diagram
Key Customization Features
- Autoscaling and real-time data support
- Timeline Filtering
- Line Interpolation
- Configurable Axis Labels and Advanced Label Positioning
- Legends (Labels & Gradient)
- Advanced Tooltips
- Data point Event Handlers
- CSS-based styling for complete visual overrides
- Compatibility with ngUpgrade
Customization capabilities in ngx-charts
masterThe framework supports several advanced customization features for fine-tuning chart appearance and behavior, including responsive layouts, real-time data, and interactive elements.
### Customization - Autoscaling - Timeline Filtering - Line Interpolation - Configurable Axis Labels - Legends (Labels & Gradient) - Advanced Label Positioning - Real-time data support - Advanced Tooltips - Responsive Layout - Data point Event Handlers - Works with ngUpgrade - Enabling/Disabling animationsAvailable Chart Types in ngx-charts
masterngx-charts provides a variety of built-in chart types for data visualization. Note that the Force Directed Graph is deprecated; users should use
ngx-graphinstead.### Chart Types - Horizontal & Vertical Bar Charts (Standard, Grouped, Stacked, Normalized) - Line - Area (Standard, Stacked, Normalized) - Pie (Explodable, Grid, Custom legends) - Donut - Gauge - Linear Gauge - Force Directed Graph (deprecated - please use [ngx-graph](https://github.com/swimlane/ngx-graph) instead) - Heatmap - Treemap - Number Cards - Bubble/Scatter - Vertical Box ChartBuild custom charts using ngx-charts building blocks
masterBeyond the standard chart library,
ngx-chartsexports various components and helpers that serve as building blocks. You can import these directly into your Angular application to construct custom charts for use cases not covered by the pre-made library.Available building blocks include:
- Legends
- Axes
- Dimension helpers
- Gradients
- Shapes
- Series of shapes
Install @swimlane/ngx-charts via npm
masterInstall the latest release of
ngx-chartsusing npm to add it to your project dependencies. Before installing, check thepackage.jsonfile in the repository to ensure compatibility with your current version of Angular.npm install @swimlane/ngx-charts --saveConstruct custom charts with ngx-charts components
masterYou can build your own custom charts by leveraging the various individual ngx-charts components that are exposed through thengx-chartsmodule.Run ngx-charts demos locally
masterTo run the project's demonstration applications on your local machine, follow these steps:
- Install dependencies using
npm i. - Start the development server using
npm start. - Open your browser and navigate to
http://localhost:9999.
npm i npm start- Install dependencies using
Build custom charts with ngx-charts components
masterYou can construct custom charts by leveraging the various ngx-charts components exposed through thengx-chartsmodule. For detailed instructions and examples on building custom visualizations, refer to the Custom Charts documentation.Customize ngx-charts styles with CSS
masterThe visual styles of ngx-charts are completely customizable through CSS. You can override the default aesthetics by targeting the chart components with your own CSS rules.Best practices for creating or adapting custom charts
masterWhen developing new charts or adapting existing ones from the
ngx-chartssource code, follow these guidelines:- Development Workflow: Start by building the chart shell within the
ngx-chartsdemo project. - Component Renaming: If copying an existing chart from the
srcfolder, ensure you rename your new components, their selectors, and their containing modules to avoid conflicts. - Tooltip Troubleshooting: If tooltips do not display correctly in your custom chart, ensure you export your new chart as a module along with
ChartCommonModule, and then import that module into your application's module (e.g.,app.module.ts).
- Development Workflow: Start by building the chart shell within the
Use the Gauge Chart component
masterThe Gauge Chart is used to display a single value within a scale. It supports customization of the scale range, segments, angles, and formatting for both the axis and the central value.