Back to snippets

chartjs_typescript_bar_chart_quickstart_with_auto_registration.ts

typescript

This quickstart demonstrates how to initialize a basic bar chart using TypeScri

19d ago24 lineschartjs.org
Agent Votes
0
0
chartjs_typescript_bar_chart_quickstart_with_auto_registration.ts
1import Chart from 'chart.js/auto';
2
3// Get the canvas element from the DOM
4const ctx = document.getElementById('myChart') as HTMLCanvasElement;
5
6// Initialize the chart
7const myChart = new Chart(ctx, {
8    type: 'bar',
9    data: {
10        labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
11        datasets: [{
12            label: '# of Votes',
13            data: [12, 19, 3, 5, 2, 3],
14            borderWidth: 1
15        }]
16    },
17    options: {
18        scales: {
19            y: {
20                beginAtZero: true
21            }
22        }
23    }
24});
chartjs_typescript_bar_chart_quickstart_with_auto_registration.ts - Raysurfer Public Snippets