A revenue area chart card built with Tailwind CSS and a small vanilla JavaScript file that draws the SVG, so no chart library is needed. This dashboard chart example shows total revenue, the change against the previous period, and revenue and costs as two smooth area series with a legend toggle and a tooltip. It fits SaaS analytics, e-commerce admin panels and finance reports.
How it works
The root section.rac-root holds one card. The header shows the total from [data-rac-total], the change badge [data-rac-change] and two legend buttons with data-rac-series="revenue" and data-rac-series="costs". A dl underneath lists costs, gross profit and margin. The chart lives in .rac-plot, which contains an empty svg[data-rac-svg] and the tooltip [data-rac-tip].
All numbers come from the DATA object at the top of script.js. On DOMContentLoaded the script computes the month labels from today (the last value is the current month, shown without a year), the totals and the change badge, then draw() measures the plot width and builds the SVG: dashed gridlines, a value axis with "nice" steps from niceStep(), month labels, and for each visible series a gradient area plus a line. Lines use monotone cubic curves from smoothPath(), so they never overshoot the data. The current month is active on load, with a guide line, two point markers and the tooltip showing revenue, costs and profit.
Moving the pointer or tapping the plot picks the nearest month. Clicking a legend button flips aria-pressed, hides that series and rescales the value axis to the remaining data.
Customization
DATA.series[].valuesinscript.js: replace with your own monthly figures; totals, labels, tooltip and table update.DATA.series[].color: line and gradient colors,#0ea5e9(sky) and#64748b(slate) by default.DATA.previousRevenue: the comparison total behind the change badge; a negative change switches the badge to rose.DATA.currencyandDATA.locale: any ISO currency such asEUR; formatting usesIntl.NumberFormat.var H = W < 480 ? 240 : 300indraw(): the chart height on phones and wider cards.max-w-3xlon thearticle: make the card wider or narrower.
Use cases
- SaaS dashboards: monthly recurring revenue against infrastructure and payroll costs.
- Online stores: sales versus cost of goods for the last twelve months.
- Agency and freelancer reports: income and expenses in one client-ready card.
Accessibility
The plot is focusable (tabindex="0") with role="group", aria-roledescription="chart" and a label that explains the arrow keys. Left and Right move between months, Home and End jump to the first and last, and a polite live region [data-rac-live] reads the month and its values. Legend buttons use aria-pressed; hidden series show a hollow dot and grey text, and at least one series always stays visible. The SVG is aria-hidden; a summary paragraph and a visually hidden table repeat every number.
Usage notes
The Inter font loads from Google Fonts. Several cards can share a page because every query is scoped to its .rac-root and gradient ids are unique per card.