MeterBarChart
The MeterBarChart provides a lightweight and simple visualization progress
toward a completion, consumption of a total, etc. It consists of a horizontal
bar that gradually fills up with color or shading as it approaches the max
value.
Import
import { MeterBarChart } from '@dynatrace/strato-components-preview/charts';
Use cases
The MeterBarChart expects a single value as an input. This value needs to be
passed to the visualisation's value prop as a Number.
You can also provide custom min and max props to set the scale of the
MeterBarChart, and if none are provided the default min will be 0 and max
will be 100.
It is also possible to delegate the component to generate the labels by setting
<MeterBarChart.Min />, <MeterBarChart.Max /> and <MeterBarChart.Value />
slots, to respectively generate automatically min, max, and value labels (the
formatting will be applied automatically).
Learn more about the data format here.
Object values
The MeterBarChart accepts object values in addition to numeric values. When
passing an object value, a valueAccessor prop needs to be specified to
indicate which field should be used as the chart's display value.
In the example above, the chart displays the value from the value field, while
the ColorRule evaluates against the count field using its own valueAccessor
prop. This enables conditional coloring based on different properties within the
data object.
Change the chart color/s
The MeterBarChart provides several ways to customize the appearance of your
data:
- Direct Color Assignment: Set a single color for the entire bar.
- Color Rules: Apply conditional coloring based on the bar's value.
Direct Color Assignment
The MeterBarChart has a default color for the bar segment, but it accepts a
color prop that can be set to any valid color string that utilizes a format
supported by web browsers, including RGB, HSL and HEX.
Using Color Rules
For more advanced coloring scenarios, you can use the ColorRule component to
apply conditional coloring based on the bar's value. This is particularly useful
for creating visual indicators for different value ranges.
Color rules can be applied based on the bar's value using different comparators:
'greater-than''less-than''greater-or-equal''less-or-equal''equals'
In the example above, we're using rules to change the bar color based on value thresholds:
- Values ≥ 80 are shown in red
- Values ≥ 60 (but < 80) are shown in orange
- Values below 60 use the default color
You can combine multiple rules to create complex coloring schemes. When multiple
rules match, the most specific rule (highest matchValue for 'greater'
comparators, lowest for 'less' comparators) will take precedence.
For more details about available comparators and options, see the Color Rules section.