Dashboard Chart Rendering#
Langfuse dashboards use a centralized, widget-based chart rendering system located in web/src/features/widgets/chart-library/. The entry point is a single <Chart> wrapper component that dispatches to the appropriate chart implementation based on a chartType prop of type DashboardWidgetChartType.
Supported Chart Types#
Nine chart types are defined in the DashboardWidgetChartType Prisma enum :
| Enum Value | Component | Use Case |
|---|---|---|
LINE_TIME_SERIES | LineChartTimeSeries | Time-bucketed line charts |
AREA_TIME_SERIES | AreaChartTimeSeries | Area/filled time charts |
BAR_TIME_SERIES | VerticalBarChartTimeSeries | Stacked/grouped bar over time |
HORIZONTAL_BAR | HorizontalBarChart | Categorical, ranked data |
VERTICAL_BAR | VerticalBarChart | Categorical columns |
PIE | PieChart | Part-of-whole distributions |
HISTOGRAM | HistogramChart | Numeric value distributions |
NUMBER | BigNumber | Single metric display |
PIVOT_TABLE | PivotTable | Multi-dimension tabular data |
The <Chart> component's renderChart() switch dispatches to each of these . If data.length > 2000 and overrideWarning is not set, a large-dataset warning is shown instead of rendering .
Data Model#
All chart components share a common DataPoint interface and accept ChartProps:
time_dimension– optional string; if ISO-formatted,<Chart>parses and localizes it to either a date string (midnight UTC) or a date-time string .dimension– optional string for categorical grouping (e.g., x-axis labels in bar charts).metric– a number or array of numbers.
The utility functions groupDataByTimeDimension() and getUniqueDimensions() (in utils.ts) are used by time-series charts to pivot the flat DataPoint[] into a Recharts-compatible grouped format, with each unique dimension value becoming a separate keyed series .
Time Series Chart Rendering#
LineChartTimeSeries is the canonical time-series implementation . Key behaviors:
- Color assignment per series: each unique dimension gets
hsl(var(--chart-N))whereN = (index % 8) + 1, cycling through 8 CSS chart variables . - Interactive legend (
legendPosition="above"): clicking a legend entry highlights that series and dims others viahighlightedDimensionstate . - Data point dots: toggleable via
showDataPointDotsprop; dots are suppressed on muted series . - Null handling:
connectNullsis always enabled .
AreaChartTimeSeries and VerticalBarChartTimeSeries follow the same pattern with their respective Recharts primitives.
Categorical Bar Chart Rendering#
VerticalBarChart renders dimension-keyed bars using Recharts <BarChart> with dataKey="metric" . The fill color comes from the CSS variable --color-metric, resolved via the ChartContainer config. A subtleFill boolean prop reduces fillOpacity to 0.3 .
HorizontalBarChart follows the same pattern with a transposed axis.
Color Assignment Strategies#
Three separate systems handle color assignment depending on context:
1. Widget chart library (CSS variables)
Inside chart-library components, series colors are assigned by index to the design-system's named CSS variables --chart-1 through --chart-8 . This makes colors automatically theme-aware (light/dark).
2. Legacy dashboard utility (getColorsForCategories)
For older dashboard cards (e.g., Tremor-based charts), getColorsForCategories maps a list of category strings to a predefined palette of 22 Tailwind color names (indigo, cyan, zinc, purple, …), cycling with random fallback if there are more categories than palette entries .
3. Score analytics (color-scales.ts)
The score analytics module uses a richer, perceptually uniform system via color-scales.ts:
- Heatmaps: OKLCH-space mono-color scales generated with
generateMonoColorScale()using the 6HEATMAP_BASE_COLORSanchors. - Categorical scores:
getScoreCategoryColors()generates OKLAB-mixed monochrome scales per score, sorting categories alphabetically first for stable, order-independent color assignment. - Boolean scores:
getScoreBooleanColors()produces a 2-step scale withTruedarker andFalselighter. - Numeric scores:
getScoreNumericColor()returns the fully-saturated base color. buildColorMappings()is the top-level builder that assembles all of the above into a singleRecord<string, string>for use in multi-score comparison views, with namespaced keys to avoid collision when two scores share the same name from different sources.
Key Consumers#
ChartScores– renders average numeric scores over time as aLINE_TIME_SERIESchart withlegendPosition="above"andshow_data_point_dots: false.CategoricalScoreChart– renders categorical score distributions as aVERTICAL_BARchart withsubtle_fill: true.
Files at a Glance#
| File | Purpose |
|---|---|
chart-library/Chart.tsx | Main dispatcher component |
chart-library/chart-props.ts | DataPoint and ChartProps types |
chart-library/utils.ts | groupDataByTimeDimension, getUniqueDimensions |
chart-library/LineChartTimeSeries.tsx | Line time-series implementation |
chart-library/VerticalBarChart.tsx | Categorical vertical bar chart |
dashboard/utils/getColorsForCategories.tsx | Legacy Tailwind color palette utility |
score-analytics/lib/color-scales.ts | OKLCH/OKLAB perceptual color scales |