ngx-charts Documentation

repository·master·Indexed 26 days ago

https://github.com/swimlane/ngx-charts

A 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.

Tokens
27.5K
Snippets
30
Records
108
Agent score
85%

What's inside ngx-charts

  1. Overview of ngx-charts

    master
    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.
  2. Overview of ngx-charts features and chart types

    master

    ngx-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
  3. Customization capabilities in ngx-charts

    master

    The 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 animations
  4. Available Chart Types in ngx-charts

    master

    ngx-charts provides a variety of built-in chart types for data visualization. Note that the Force Directed Graph is deprecated; users should use ngx-graph instead.

    ### 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 Chart
  5. Build custom charts using ngx-charts building blocks

    master

    Beyond the standard chart library, ngx-charts exports 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
  6. Install @swimlane/ngx-charts via npm

    master

    Install the latest release of ngx-charts using npm to add it to your project dependencies. Before installing, check the package.json file in the repository to ensure compatibility with your current version of Angular.

    npm install @swimlane/ngx-charts --save
  7. Best practices for creating or adapting custom charts

    master

    When developing new charts or adapting existing ones from the ngx-charts source code, follow these guidelines:

    • Development Workflow: Start by building the chart shell within the ngx-charts demo project.
    • Component Renaming: If copying an existing chart from the src folder, 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).