Mini Chart Card

Visually represent major data trends at a glance with this dynamic, data-driven mini chart card.

This is a convenient dashboard component for displaying metrics like user growth, revenue, or traffic sources. It pairs a key statistic with a chart graphic that is rendered from actual data using the popular Chart.js library.

Screenshot of three dashboard cards, each showing a statistical figure and a different type of chart.

Get Source Code Preview

About this Component

Unlike a static graphic, this template uses a JavaScript charting library called Chart.js to draw real, data-driven charts. This means you can easily feed it your own numbers to generate visualizations. The example provides the setup for a line, bar, and pie chart, all styled for a minimal "mini chart" look suitable for dashboards.

Features

Code Breakdown

HTML Structure

Each card is a simple div containing a header for the text and a container for the chart. Inside the chart container is a single canvas element with a unique id (e.g., id="lineChart"). The JavaScript will use this id to find the canvas and draw the chart on it.

JavaScript Logic

The functionality requires two script tags, placed at the end of your body.

  1. Chart.js Library: The first script tag imports the Chart.js library from a CDN. This must be included for the charts to work.
  2. Chart Configuration: The second script contains your custom logic. It finds each canvas element by its id. For each one, it creates a new Chart instance, passing it the canvas context and a configuration object. This object specifies the chart type (e.g., 'line'), the data (including labels for the axes and datasets with your numbers), and the options for customizing the appearance. The data property is where you will insert your own data.

Code

Here is the complete code. To adapt it, replace the placeholder data inside the data properties in the JavaScript with your own values and labels.

View Output