suiss/ui ยท Chart
Line Chart
Ten line charts for trends over time, from a single smooth line to dots, labels, goals, forecasts and several series.
Line Chart is an open-source chart from suiss/ui for React, React Native, SwiftUI and Jetpack Compose. The @esuiss/ui CLI copies its source into your project, so you own the code.
Line charts follow a trend across time. Start with the default for one series, add dots or printed values when each reading matters, draw a goal line to show a target, and continue the line as a dashed forecast for values that have not happened yet. Linear and step lines avoid suggesting values between readings, and the multiple and interactive variants compare several series on the same axes.
Each chart is built on the Chart and Card components.
Every variant below is its own registry item, so you can add only the ones you need. Each one renders the same design on React, React Native, SwiftUI and Jetpack Compose.
Default
A single smooth line through six months of values, without point markers.
The starting line chart: one smooth series without point markers, a month axis and a tooltip. Use it to show a trend over time when the overall shape matters more than individual readings.
Replace chartData, point each dataKey at your fields and set the label and color in chartConfig. Change the curve with type on the line, or set dot to show markers. Focus the chart and use the arrow keys to move the tooltip between months.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Usage
Web preview
The baseline line chart inside a Card: one series drawn as a natural curve with a month axis, a dashed horizontal grid and a tooltip. There is no value axis.
Replace chartData with your records and change each dataKey to match your fields. Set the label and color in chartConfig, and change the curve with the type prop on Line. The component takes no props.
Installation
-
Target iOS 17 or later.
-
Copy the theme files every view uses:
- Copy the source and every file it uses:
- Add the files to your app target.
- Apply the Compose compiler plugin, enable Compose, set
compileSdkto 37 or higher andminSdkto 24 or higher, and add the dependencies:
- Copy the theme files every view uses:
- Copy the source and every file it uses:
- Update the
com.esuiss.uipackage names to match your project.
Usage
Dots
A weight trend with a dot at every monthly reading and a fixed value axis on the right.
A health-style weight card with a dot on every monthly reading and a fixed value axis on the right. The dots make it clear where measurements actually exist, so use this variant when readings are sparse or irregular.
Replace the readings in chartData and rename weight in the data, the line and chartConfig. Set the value axis domain and ticks to suit your numbers, and change the unit in the tooltip formatter. The headline value and the change below it are static text, so update them with the data or compute them from it.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Follow the manual steps under Default and copy this variant's source instead.
Usage
Web preview
Ten monthly weights drawn with type="linear" and a dot on every reading, plus a larger dot for the touched point. A value axis on the right covers a fixed range, and the tooltip formats values in kilograms. The header shows the latest weight and the change since January as static text.
Replace the weight array in chartData and update the header text to match. Adjust the YAxis domain and ticks for your range. The component takes no props.
Installation
Follow the manual steps under Default and copy this variant's source instead.
Usage
Forecast
A solid line for actual values that continues as a dashed forecast over a shaded future range.
Actual values drawn as a solid line that continues as a dashed forecast over a shaded future period. Use it whenever you show projections next to history and need readers to tell them apart.
Fill the actual and forecast arrays and start the forecast with the last actual value so the lines meet; at that point the tooltip lists both values. Move the shaded period with x1 and x2 on the reference area. Both series share one color in chartConfig, so the dash pattern, the shading and the series names in the tooltip tell them apart.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Follow the manual steps under Default and copy this variant's source instead.
Usage
Web preview
Two series share one axis: actual fills the first nine months and forecast continues from September, drawn with strokeDasharray. A ReferenceArea shades September to December to mark the forecast period. Missing values are null, so each line stops where its data ends.
Replace the actual and forecast arrays; the forecast starts at the index set in chartData. Move the ReferenceArea x1 and x2 to match your forecast range. The component takes no props.
Installation
Follow the manual steps under Default and copy this variant's source instead.
Usage
Goal Dots
Nightly sleep hours with a goal line and dots colored green or orange depending on whether the goal was met.
Nightly sleep plotted against a dashed goal line, with each dot colored green if the goal was met and orange if not. Pick it over the plain goal chart when readers should spot hits and misses at a glance.
Replace chartData and set GOAL to your target; the dot colors follow the comparison. Adjust the value axis domain and ticks, and change the two dot colors in the custom dot renderer. The headline figure is static text, so wire it up to real values. Color alone marks a hit or miss on the chart, so keep a text explanation like the one in the header.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Follow the manual steps under Default and copy this variant's source instead.
Usage
Web preview
Seven nights of sleep drawn as a monotone line. The dot prop is a function that colors each point by comparing it with GOAL, and a dashed green ReferenceLine marks the goal itself. The tooltip formats values as hours and minutes.
Replace chartData with your nightly hours and set GOAL. The header average is static text, so update it with your own value. The component takes no props.
Installation
Follow the manual steps under Default and copy this variant's source instead.
Usage
Goal
Daily step counts plotted against a labeled dashed goal line at 10,000 steps.
Daily steps as a line with dots, plotted against a labeled dashed goal line. Use it when a single target gives the values their meaning, such as quotas, budgets or fitness goals.
Replace chartData and set GOAL to your target. Change the label on the ReferenceLine, the unit in the tooltip formatter and the axis tickFormatter to fit your metric. The value axis scales to the data only, so set a domain if the goal can fall outside it. Focus the chart and use the arrow keys to step through the days.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Follow the manual steps under Default and copy this variant's source instead.
Usage
Web preview
Seven days of steps drawn as a monotone line with dots, a value axis in thousands on the right and a labeled dashed ReferenceLine at GOAL. The tooltip formats the count with thousands separators.
Replace chartData with your daily values and set GOAL. The component takes no props.
Installation
Follow the manual steps under Default and copy this variant's source instead.
Usage
Interactive
Monthly temperatures for several cities, with chips to show or hide each city and an average, high or low switch.
Monthly temperatures for several cities with chips to show or hide each city and a switch between average, high and low. A row of stats under the chart shows each city's range and follows the cursor month. Use it as a pattern for comparing many series where readers pick which ones to see.
Replace CITIES with your series and add a label and color for each to chartConfig; the visible state sets which ones start visible. The high and low modes come from a demo formula, so replace temperature with real values and fit the fixed value axis domain to your range, since values outside it are clipped. The last visible city can't be hidden, and new lines draw in with an animation that is skipped when reduced motion is preferred.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Follow the manual steps under Default and copy this variant's source instead.
Usage
Web preview
One line per visible city across twelve months. A ToggleGroup switches between average, high and low temperatures, and a row of Toggle chips shows or hides each city, keeping at least one on. Touching the plot reports the month through onActiveIndexChange, and the summary under the chart switches from each city's range to its value for that month. The lines animate with animationDuration={650} and animationEasing="ease-in-out".
Replace CITIES with your series and monthly values, and add a matching entry to chartConfig and SWATCH for each. The high and low values are derived in temperature(), so replace that with real data. The component takes no props.
Installation
The CLI also adds what it builds on: Card, Chart, Text, Toggle, Toggle Group.
Follow the manual steps under Default and copy this variant's source instead.
Usage
Labeled
A single line with a dot and a printed value at every point, and no grid.
A single smooth line with a dot and a printed value at every point and no grid. Choose it for short series where readers want the exact numbers without hovering.
Replace chartData, point each dataKey at your fields and set the label and color in chartConfig. The position prop on LabelList moves the value labels; raise the chart's top margin if they get clipped. Labels overlap on long series, so keep it to a dozen points or fewer.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Follow the manual steps under Default and copy this variant's source instead.
Usage
Web preview
One natural curve with dots on each month and a LabelList above every point, so values are readable without touching the chart. There is no grid; a month axis and a tooltip remain.
Replace chartData with your records and change each dataKey to match your fields. Change position and offset on the LabelList to move the labels. The component takes no props.
Installation
Follow the manual steps under Default and copy this variant's source instead.
Usage
Linear
A single line drawn with straight segments between readings instead of a smoothed curve.
One series joined by straight segments instead of a smoothed curve. Prefer it to the default when smoothing would imply values between readings that were never measured.
Replace chartData, point each dataKey at your fields and set the label and color in chartConfig. Focus the chart and use the arrow keys to move the tooltip between months.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Follow the manual steps under Default and copy this variant's source instead.
Usage
Web preview
One series with type="linear", so each month connects to the next with a straight segment. It has a month axis, a dashed grid and a tooltip.
Replace chartData with your records and change each dataKey to match your fields. Set the label and color in chartConfig. The component takes no props.
Installation
Follow the manual steps under Default and copy this variant's source instead.
Usage
Multiple
Two lines compared on the same axes, with a legend identifying each series.
Two series as smooth lines on shared axes, with a legend below. Use it to compare how two metrics move over the same period.
Replace chartData and rename the series keys in the data, both Line elements and chartConfig. Add a Line with its own config entry for each extra series; the legend and tooltip pick it up. Beyond four or five lines, consider the interactive variant that lets readers toggle series.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Follow the manual steps under Default and copy this variant's source instead.
Usage
Web preview
Desktop and mobile series drawn as monotone lines on the same axis. A legend below the plot names both series, and the tooltip lists each value for the touched month.
Replace chartData with your records and change each dataKey to match your fields. Add a Line and a chartConfig entry for each extra series; the legend picks them up. The component takes no props.
Installation
Follow the manual steps under Default and copy this variant's source instead.
Usage
Step
A single line drawn as horizontal steps, holding each value until the next reading.
A single line drawn as flat steps that hold each value until the next reading. It fits values that change in discrete jumps, like prices, plan tiers or headcount.
Replace chartData, point each dataKey at your fields and set the label and color in chartConfig. Set the curve type to stepAfter or stepBefore to move where each jump happens. Focus the chart and use the arrow keys to move the tooltip between months.
Installation
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Follow the manual steps under Default and copy this variant's source instead.
Usage
Web preview
One series with type="step", which draws flat runs and vertical jumps instead of slopes. Use it for values that change at discrete moments. It has a month axis, a dashed grid and a tooltip.
Replace chartData with your records and change each dataKey to match your fields. Set the label and color in chartConfig. The component takes no props.
Installation
Follow the manual steps under Default and copy this variant's source instead.