Skip to Content
DataCards 2.2.4 is released 🎉
DocumentationCardsOutput CardsArea Chart Card

Area Chart Card

Card type: areaChart

Area chart card

The area chart card displays an area chart from tabular data. You can control the area type, colors, opacity, and various display options.

In addition to the common parameters the areaChart card has the following configuration options:

NameTypeRequiredDefaultDescription
valuelist of dictYesThe data to be plotted. Each dict represents a data point.
fillCardboolNofalseWhen set to True, the chart will fill the entire card space including the header area. When False (default), the chart will be positioned below the header.
label_overridedictNoOptional: pretty labels for data series.
chart_optionsdictYesChart configuration options. See table below.

Chart Options

NameTypeRequiredDefaultDescription
xKeystrYesThe property in each dict to use for the x-axis values.
yKeyslist of strYesThe properties in each dict to use for the y-axis values (can be multiple series).
fillKeyslist of strNoThe properties in each dict to use for the fill colors of each series.
areaType”natural”, “linear”, “step”No"natural"The type of area curve to use.
fillOpacitynumberNo0.4Opacity of the filled area (0-1).
strokeWidthnumberNo2Width of the stroke line.
defaultColors”monochrome” or “multicolor”No"monochrome"Fallback color scheme if no color is provided in the data.
fontSizestrNo(auto)Font size for labels/tooltips. (if not set, this scales with the card size).
showLegendboolNotrueWhether to show the legend below the chart.
showGridboolNotrueWhether to show the grid lines.
showYAxisboolNotrueWhether to show the y-axis.
margindictNo{top: 15, right: 15, bottom: 15, left: -10}Chart margins.
xAxisConfigdictNo{tickLine: false, axisLine: false, tickMargin: 8, maxChars: 3}X-axis configuration (tickLine, axisLine, tickMargin, maxChars).
yAxisConfigdictNo{tickLine: false, axisLine: false, tickMargin: 8, maxChars: 10}Y-axis configuration (tickLine, axisLine, tickMargin, maxChars).
gridConfigdictNo{vertical: true, horizontal: true}Grid configuration (vertical, horizontal).

Axis labels

X-axis labels are automatically truncated to 3 characters and Y-axis labels to 10 characters to prevent overcrowding. You can override this using maxChars in xAxisConfig or yAxisConfig.

Area Types

  • "natural": Smooth curved area (default)
  • "linear": Straight line connections between points
  • "step": Step-like area with horizontal and vertical segments

Examples

Simple Area Chart

This example shows a basic area chart with a single data series.

import polars as pl # Create some data df = pl.DataFrame({ "month": ["January", "February", "March", "April", "May", "June"], "visitors": [186, 305, 237, 73, 209, 214], }) # Convert to the format expected by the area chart data = df.to_dicts() # Override labels label_override = { "visitors": {"label": "Visitors"}, } datacards.publish.card( type='areaChart', value=data, label="Website Visitors", chart_options={ "xKey": "month", "yKeys": ["visitors"], }, label_override=label_override, logic_view_size=(4,2), )
Simple area chart example

Multi-Series Area Chart

This example demonstrates multiple data series with different colors. Each series gets its own area with automatic color assignment.

import polars as pl # Create some data df = pl.DataFrame({ "month": ["January", "February", "March", "April", "May", "June"], "desktop": [186, 305, 237, 73, 209, 214], "mobile": [120, 200, 180, 90, 150, 160], }) # Convert to the format expected by the area chart data = df.to_dicts() # Override labels label_override = { "desktop": {"label": "Desktop"}, "mobile": {"label": "Mobile"}, } datacards.publish.card( type='areaChart', value=data, label="Traffic by Device", chart_options={ "xKey": "month", "yKeys": ["desktop", "mobile"], "defaultColors": "multicolor", }, label_override=label_override, logic_view_size=(4,2), )
Multi-series area chart example

Step Area Chart

This example shows a step area chart, which is useful for data that changes at discrete intervals.

import polars as pl # Create some data df = pl.DataFrame({ "time": ["00:00", "04:00", "08:00", "12:00", "16:00", "20:00"], "temperature": [15, 12, 18, 25, 28, 22], }) # Convert to the format expected by the area chart data = df.to_dicts() # Override labels label_override = { "temperature": {"label": "Temperature (°C)"}, } datacards.publish.card( type='areaChart', value=data, label="Daily Temperature", chart_options={ "xKey": "time", "yKeys": ["temperature"], "areaType": "step", "xAxisConfig": {"maxChars": 5}, "margin": {"top": 15, "right": 25, "bottom": 10, "left": -10} }, label_override=label_override, logic_view_size=(4,2), )
Step area chart example

Area Chart with Custom Colors

This example demonstrates how to specify custom colors for each data series using the fillKeys option.

import polars as pl # Create some data df = pl.DataFrame({ "quarter": ["Q1", "Q2", "Q3", "Q4"], "revenue": [1000, 1200, 1100, 1400], "costs": [800, 900, 850, 1000], "revenue_color": ["#10b981", "#10b981", "#10b981", "#10b981"], "costs_color": ["#ef4444", "#ef4444", "#ef4444", "#ef4444"], }) # Convert to the format expected by the area chart data = df.to_dicts() # Override labels label_override = { "revenue": {"label": "Revenue"}, "costs": {"label": "Costs"}, } datacards.publish.card( type='areaChart', value=data, label="Financial Overview", chart_options={ "xKey": "quarter", "yKeys": ["revenue", "costs"], "fillKeys": ["revenue_color", "costs_color"], "areaType": "linear", "fillOpacity": 0.5, }, label_override=label_override, logic_view_size=(4,2), )
Area chart with custom colors example
Last updated on