Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Chart

The lens-chart component provides a styled wrapper for visualizing data using Chart.js. It handles dynamic display behaviors like toggling chart visibility, showing hints, and rendering a fallback message when no data is available. Some Options are setable via ChartOption and some are set via props.

Example of a lens chart

The component is constructed from a title and a chart. There is a slot after the title and chart for customization. The chart does render either totals or stratifier from the lens-results.


Props

Non of the props are required, however without datakey prop the chart does not known which data to render and will be empty.

NameTypeDefaultDescription
titlestring""Title displayed above the chart.
indexAxisstring"x"Determines the main axis for data display. Use 'y' to flip the chart orientation (horizontal bars instead of vertical)
xAxisTitlestring""Title below the x-axis.
yAxisTitlestring""Title below the y-axis.
clickToAddStateboolean"false"With this prop set to true it will add the clicked item to the search. The rendered element must have the same name as the catalogue item.
headersMap<string, string>""Maps internal result keys to human-readable labels for display. For example, mapping "gender_m" to "Male" or "age_65_plus" to "65+ years".
displayLegendsboolean""With this option a legend of all data items is render below the graph.
chartTypeChartTypeRegistry""Which type of chart is rendered, see types
scaleTypestring"linear"Sets the scale type of the chart. Either "linear" or "logarithmic"
dataKeystring""Looks up the data in the Result store.
perSiteboolean"false"When true, displays aggregated totals per site/location instead of overall totals.
groupRangenumber""lets the user define a range for the labels when only single values are used eg. '60' -> '60 - 69'.
groupingDividerstring""Is the char that combines subgroups into their supergroups like C30, C31.1 and C31.2 into C31
filterRegexstring""Filters data according to the provided regular expression.
groupingLabelstring""Sets divider for grouping stratifier together.
viewScalesboolean"true"Displays the scales on the x-axis and y- axis.
backgroundColorstring[]""Expects an array with hex color strings. These colors will be set in the order which are provided. There is no possibility to map results to certain colors. If no color is set, there are the lens default colors. If you provide more results then colors, they will repeat from the beginning.
backgroundHoverColorstring[]""Similar functionality as the background color, instead the hover colors.

Example

<lens-chart
    title="Gender"
    datakey="gender"
    chartType="pie"
    displayLegends="true"
></lens-chart>

Styling

Part NameDescription
lens-chart-wrapperRoot wrapper with grid layout and background color.
lens-chart-info-button-wrapperPositioned top-right; holds the optional info button.
lens-chart-titleRenders the chart’s title, centered.
lens-chart-overlayCovers the chart area to display messages (e.g. no data).
lens-chart-no-data-availableStyled message shown when there is no chart data.
lens-chart-container-min-width-0Wraps the canvas; forces min-width: 0 for responsiveness.
lens-chart-canvasThe chart rendering surface. Includes width/max-height rules.