Carbon Charts

repository·main·Indexed 21 days ago

https://github.com/carbon-design-system/carbon-charts

A comprehensive charting library providing 26 distinct chart types. It offers dedicated component libraries for vanilla JavaScript (@carbon/charts), Angular (@carbon/charts-angular), React (@carbon/charts-react), Svelte (@carbon/charts-svelte), and Vue.js (@carbon/charts-vue).

Tokens
23K
Snippets
110
Records
137
Agent score
75%

What's inside Carbon Charts

  1. Overview of Carbon Charts

    main

    Carbon Charts is a component library providing 26 different chart types. It is designed to work across multiple environments, offering dedicated packages for:

    • Vanilla JavaScript (@carbon/charts)
    • Svelte (@carbon/charts-svelte)
    • React (@carbon/charts-react)
    • Vue.js (@carbon/charts-vue)
    • Angular (@carbon/charts-angular)
  2. Install Carbon Charts Angular

    main

    To install the latest version of Carbon Charts for Angular, use npm or yarn. Note that the current documentation refers to the @next distribution tag for the latest features.

    If you are using an older version of Angular, you should use specific distribution tags instead of the default, such as:

    • @carbon/charts-angular@angular12
    • @carbon/charts-angular@angular16
    • @carbon/charts-angular@angular17
    npm install -S @carbon/charts-angular@next
    
    # Or using Yarn
    yarn add @carbon/charts-angular@next
  3. Access Carbon Charts documentation and examples

    main

    The official Carbon Charts documentation website includes interactive StackBlitz examples for every chart type across all supported frameworks. You can explore these examples and find implementation details at the official site.

    https://charts.carbondesignsystem.com/
  4. Avoid SSR issues with Dynamic Imports

    main

    Because @carbon/charts expects a window object, you should dynamically import the chart components within Svelte's onMount function to prevent errors during Server-Side Rendering (SSR).

    <script>
    	import '@carbon/charts-svelte/styles.css'
    	import { onMount } from 'svelte'
    
    	let Chart = $state()
    
    	onMount(async () => {
    		const charts = await import('@carbon/charts-svelte')
    		Chart = charts.BarChartSimple
    	})
    </script>
    
    <Chart
    	data={[
    		{ group: 'Qty', value: 65000 },
    		{ group: 'More', value: 29123 },
    		{ group: 'Sold', value: 35213 },
    		{ group: 'Restocking', value: 51213 },
    		{ group: 'Misc', value: 16932 }
    	]}
    	options={{
    		theme: 'white',
    		title: 'Simple bar (discrete)',
    		height: '400px',
    		axes: {
    			left: { mapsTo: 'value' },
    			bottom: { mapsTo: 'group', scaleType: 'labels' }
    		}
    	}} />
  5. Run the Carbon Charts documentation website locally

    main

    To run the Carbon Charts documentation website in a development environment, install the dependencies and start the development server. You can use the --open flag to automatically open the application in your default web browser.

    yarn install
    yarn dev
    
    # or start the server and open the app in a new browser tab
    yarn dev -- --open