Top Related Projects
Simple HTML5 Charts using the <canvas> tag
Bring data to life with SVG, Canvas and HTML. :bar_chart::chart_with_upwards_trend::tada:
📊 Interactive JavaScript Charts built on SVG
Highcharts JS, the JavaScript charting framework
📊 Re-usable, easy interface JavaScript chart library based on D3.js
Redefined chart library built with React and D3
Quick Overview
ngx-charts is a declarative charting framework for Angular applications. It provides a wide range of customizable chart types and is built on top of D3.js, offering a powerful and flexible solution for data visualization in Angular projects.
Pros
- Seamless integration with Angular applications
- Wide variety of chart types and customization options
- Built on D3.js, providing powerful data manipulation capabilities
- Responsive design and animations out of the box
Cons
- Learning curve for developers new to D3.js concepts
- Limited documentation for advanced customizations
- Performance may degrade with large datasets
- Some chart types may require additional configuration for optimal display
Code Examples
- Basic Bar Chart
import { Component } from '@angular/core';
@Component({
selector: 'app-bar-chart',
template: `
<ngx-charts-bar-vertical
[view]="[700, 400]"
[results]="data"
[xAxis]="true"
[yAxis]="true"
[legend]="true"
[showXAxisLabel]="true"
[showYAxisLabel]="true"
xAxisLabel="Country"
yAxisLabel="Population">
</ngx-charts-bar-vertical>
`
})
export class BarChartComponent {
data = [
{ name: 'Germany', value: 8940000 },
{ name: 'USA', value: 5000000 },
{ name: 'France', value: 7200000 }
];
}
- Pie Chart with Custom Colors
import { Component } from '@angular/core';
@Component({
selector: 'app-pie-chart',
template: `
<ngx-charts-pie-chart
[view]="[700, 400]"
[results]="data"
[legend]="true"
[labels]="true"
[doughnut]="false"
[scheme]="colorScheme">
</ngx-charts-pie-chart>
`
})
export class PieChartComponent {
data = [
{ name: 'Germany', value: 8940000 },
{ name: 'USA', value: 5000000 },
{ name: 'France', value: 7200000 }
];
colorScheme = {
domain: ['#5AA454', '#A10A28', '#C7B42C']
};
}
- Line Chart with Multiple Series
import { Component } from '@angular/core';
@Component({
selector: 'app-line-chart',
template: `
<ngx-charts-line-chart
[view]="[700, 400]"
[results]="multi"
[xAxis]="true"
[yAxis]="true"
[legend]="true"
[showXAxisLabel]="true"
[showYAxisLabel]="true"
xAxisLabel="Year"
yAxisLabel="Population">
</ngx-charts-line-chart>
`
})
export class LineChartComponent {
multi = [
{
name: 'Germany',
series: [
{ name: '2010', value: 7300000 },
{ name: '2011', value: 8940000 }
]
},
{
name: 'USA',
series: [
{ name: '2010', value: 7870000 },
{ name: '2011', value: 8270000 }
]
}
];
}
Getting Started
-
Install ngx-charts:
npm install @swimlane/ngx-charts
-
Import NgxChartsModule in your app.module.ts:
import { NgxChartsModule } from '@swimlane/ngx-charts'; @NgModule({ imports: [ NgxChartsModule ] })
Competitor Comparisons
Simple HTML5 Charts using the <canvas> tag
Pros of Chart.js
- Wider browser compatibility, including older versions
- Extensive documentation and large community support
- Lightweight and fast rendering, especially for simple charts
Cons of Chart.js
- Less customizable and flexible compared to ngx-charts
- Limited built-in chart types and advanced features
- Requires more manual configuration for complex visualizations
Code Comparison
Chart.js:
new Chart(ctx, {
type: 'bar',
data: {
labels: ['Red', 'Blue', 'Yellow'],
datasets: [{
label: 'My Dataset',
data: [12, 19, 3]
}]
}
});
ngx-charts:
<ngx-charts-bar-vertical
[view]="[700, 400]"
[results]="[
{name: 'Red', value: 12},
{name: 'Blue', value: 19},
{name: 'Yellow', value: 3}
]"
[xAxis]="true"
[yAxis]="true"
[legend]="true">
</ngx-charts-bar-vertical>
Chart.js offers a more programmatic approach with JavaScript configuration, while ngx-charts provides a declarative Angular component-based implementation. ngx-charts simplifies the creation of complex charts with built-in features, whereas Chart.js requires more manual setup but offers greater flexibility for custom implementations.
Bring data to life with SVG, Canvas and HTML. :bar_chart::chart_with_upwards_trend::tada:
Pros of d3
- Highly flexible and customizable, allowing for complex and unique visualizations
- Extensive documentation and large community support
- Can be used with various frameworks or vanilla JavaScript
Cons of d3
- Steeper learning curve due to its low-level nature
- Requires more code to create basic charts
- Less out-of-the-box responsiveness for different screen sizes
Code Comparison
d3:
const svg = d3.select("body").append("svg")
.attr("width", 400)
.attr("height", 300);
svg.selectAll("rect")
.data(data)
.enter()
.append("rect")
.attr("x", (d, i) => i * 70)
.attr("y", (d, i) => 300 - 10 * d)
.attr("width", 65)
.attr("height", (d, i) => d * 10);
ngx-charts:
<ngx-charts-bar-vertical
[view]="[400, 300]"
[results]="data"
[xAxis]="true"
[yAxis]="true"
[legend]="true"
[showXAxisLabel]="true"
[showYAxisLabel]="true">
</ngx-charts-bar-vertical>
The d3 example shows more manual control over chart creation, while ngx-charts offers a more declarative approach with pre-built components.
📊 Interactive JavaScript Charts built on SVG
Pros of ApexCharts.js
- More extensive chart types and customization options
- Better browser compatibility, including IE11 support
- Responsive and mobile-friendly design out of the box
Cons of ApexCharts.js
- Larger file size, which may impact load times
- Steeper learning curve due to more complex API
- Not specifically designed for Angular integration
Code Comparison
ngx-charts:
<ngx-charts-bar-vertical
[view]="[700, 400]"
[scheme]="colorScheme"
[results]="data"
[xAxis]="true"
[yAxis]="true"
[legend]="true"
[showXAxisLabel]="true"
[showYAxisLabel]="true"
[xAxisLabel]="'Country'"
[yAxisLabel]="'Population'">
</ngx-charts-bar-vertical>
ApexCharts.js:
var options = {
chart: { type: 'bar' },
series: [{ data: [30, 40, 45, 50, 49, 60, 70, 91, 125] }],
xaxis: { categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep'] }
};
var chart = new ApexCharts(document.querySelector("#chart"), options);
chart.render();
Both libraries offer powerful charting capabilities, but ngx-charts is more tightly integrated with Angular, while ApexCharts.js provides a wider range of chart types and customization options. The choice between them depends on specific project requirements, such as Angular integration, browser support, and desired chart complexity.
Highcharts JS, the JavaScript charting framework
Pros of Highcharts
- More extensive chart types and customization options
- Better browser compatibility, including older versions
- Larger community and more comprehensive documentation
Cons of Highcharts
- Commercial license required for most use cases
- Steeper learning curve due to more complex API
- Larger file size, potentially impacting page load times
Code Comparison
ngx-charts:
<ngx-charts-line-chart
[view]="[700, 400]"
[scheme]="colorScheme"
[results]="multi"
[gradient]="gradient"
[xAxis]="showXAxis"
[yAxis]="showYAxis"
[legend]="showLegend"
[showXAxisLabel]="showXAxisLabel"
[showYAxisLabel]="showYAxisLabel"
[xAxisLabel]="xAxisLabel"
[yAxisLabel]="yAxisLabel"
[autoScale]="autoScale"
(select)="onSelect($event)">
</ngx-charts-line-chart>
Highcharts:
Highcharts.chart('container', {
chart: { type: 'line' },
title: { text: 'My Chart' },
xAxis: { categories: ['A', 'B', 'C'] },
yAxis: { title: { text: 'Values' } },
series: [{
name: 'Series 1',
data: [1, 2, 3]
}]
});
Both libraries offer powerful charting capabilities, but ngx-charts is more Angular-centric and easier to integrate into Angular projects. Highcharts provides more flexibility and options but requires more setup and configuration.
📊 Re-usable, easy interface JavaScript chart library based on D3.js
Pros of billboard.js
- Framework-agnostic, can be used with various JavaScript libraries or frameworks
- Extensive documentation and examples, making it easier for developers to get started
- Supports a wider variety of chart types out of the box
Cons of billboard.js
- Less seamless integration with Angular applications compared to ngx-charts
- May require more manual configuration for complex visualizations
- Steeper learning curve for developers already familiar with Angular ecosystem
Code Comparison
billboard.js:
var chart = bb.generate({
data: {
columns: [
["data1", 30, 200, 100, 400, 150, 250],
["data2", 50, 20, 10, 40, 15, 25]
],
type: "line"
}
});
ngx-charts:
<ngx-charts-line-chart
[view]="view"
[scheme]="colorScheme"
[results]="multi"
[gradient]="gradient"
[xAxis]="showXAxis"
[yAxis]="showYAxis"
[legend]="showLegend"
[showXAxisLabel]="showXAxisLabel"
[showYAxisLabel]="showYAxisLabel"
[xAxisLabel]="xAxisLabel"
[yAxisLabel]="yAxisLabel">
</ngx-charts-line-chart>
Both libraries offer powerful charting capabilities, but billboard.js provides more flexibility across different frameworks, while ngx-charts offers tighter integration with Angular applications. The choice between them depends on the specific project requirements and the development team's expertise.
Redefined chart library built with React and D3
Pros of recharts
- Built with React, making it a natural fit for React-based applications
- Highly customizable with a declarative API, allowing for easy chart configuration
- Supports responsive design out of the box, adapting to different screen sizes
Cons of recharts
- Limited to React applications, unlike ngx-charts which works with Angular
- May have a steeper learning curve for developers not familiar with React concepts
- Fewer built-in chart types compared to ngx-charts
Code Comparison
recharts:
import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend } from 'recharts';
<LineChart width={600} height={300} data={data}>
<Line type="monotone" dataKey="value" stroke="#8884d8" />
<CartesianGrid stroke="#ccc" />
<XAxis dataKey="name" />
<YAxis />
</LineChart>
ngx-charts:
<ngx-charts-line-chart
[view]="[600, 300]"
[results]="data"
[xAxis]="true"
[yAxis]="true"
[legend]="true"
[showXAxisLabel]="true"
[showYAxisLabel]="true">
</ngx-charts-line-chart>
Both libraries offer straightforward ways to create charts, with recharts using a more component-based approach typical of React, while ngx-charts uses a single component with multiple input properties, which is common in Angular applications.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
ngx-charts
Declarative Charting Framework for Angular!
ngx-charts is unique because we don't merely wrap d3, nor any other chart engine for that matter. It is using Angular to render and animate the SVG elements with all of its binding and speed goodness, and uses d3 for the excellent math functions, scales, axis and shape generators. By having Angular do all of the rendering it opens us up to endless possibilities the Angular platform provides such as AoT, SSR, etc.
Data visualization is a science but that doesn't mean it has to be ugly. One of the big efforts we've made while creating this project is to make the charts aesthetically pleasing. The styles are also completely customizable through CSS, so you can override them as you please.
Also, constructing custom charts is possible by leveraging the various ngx-charts components that are exposed through the ngx-charts module.
For more info, check out the documentation and the demos.
Features
Chart Types
- Horizontal & Vertical Bar Charts (Standard, Grouped, Stacked, Normalized)
- Line
- Area (Standard, Stacked, Normalized)
- Pie (Explodable, Grid, Custom legends)
- Bubble
- Donut
- Gauge (Linear & Radial)
- Heatmap
- Treemap
- Number Cards
- Sankey Diagram
Customization
- Autoscaling
- Timeline Filtering
- Line Interpolation
- Configurable Axis Labels
- Legends (Labels & Gradient)
- Advanced Label Positioning
- Real-time data support
- Advanced Tooltips
- Data point Event Handlers
- Works with ngUpgrade
Install
To use ngx-charts in your project install it via npm:
npm i @swimlane/ngx-charts --save
Custom Charts
To learn how to use the ngx-charts components to build custom charts and find examples, please refer to our Custom Charts Page.
Release
- Checkout master (
git checkout master
) - Pull master (
git pull
) - Refresh node modules (
npm ci
) - Run tests (
npm test
) - Examine log to determine next version (X.Y.Z)
- Run
git checkout -b release/X.Y.Z
- Update version in
projects/swimlane/ngx-charts/package.json
. - Update changelog in
projects/docs/changelog.md
- Run
git commit -am "(release): X.Y.Z"
- Run
git tag X.Y.Z
- Run
git push origin HEAD --tags
- Run
npm run publish:lib
- Submit PR
Credits
ngx-charts
is a Swimlane open-source project; we believe in giving back to the open-source community by sharing some of the projects we build for our application. Swimlane is an automated cyber security operations and incident response platform that enables cyber security teams to leverage threat intelligence, speed up incident response and automate security operations.
SecOps Hub is an open, product-agnostic, online community for security professionals to share ideas, use cases, best practices, and incident response strategies.
Top Related Projects
Simple HTML5 Charts using the <canvas> tag
Bring data to life with SVG, Canvas and HTML. :bar_chart::chart_with_upwards_trend::tada:
📊 Interactive JavaScript Charts built on SVG
Highcharts JS, the JavaScript charting framework
📊 Re-usable, easy interface JavaScript chart library based on D3.js
Redefined chart library built with React and D3
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot