Skip to content

MetricCard

The optional sparkline fills the lower portion of the card. Omit SetSparklineData (or pass nil) to show a plain metric with no chart.

MetricCard preview

MetricCard is a dashboard tile that shows a primary value, label, trend indicator, and an optional sparkline in the lower portion of the card.

Constructor func NewMetricCard() *MetricCard

Usage

card := components.NewMetricCard().
SetLabel("Requests / sec").
SetNumericValue(1420, "%.0f").
SetUnit("rps").
SetTrend(components.TrendUp, "+12%", true).
SetSparkline([]float64{980, 1100, 1250, 1420}).
SetShowSpark(true)
fmt.Println(card != nil)

Methods

Method Signature Description
AddSparkValue func (m *MetricCard) AddSparkValue(value float64, maxLen int) *MetricCard AddSparkValue appends a value to sparkline with rolling window
GetFieldHeight func (m *MetricCard) GetFieldHeight() int GetFieldHeight returns preferred height
GetTrend func (m *MetricCard) GetTrend() Trend GetTrend returns the current trend
GetValue func (m *MetricCard) GetValue() string GetValue returns the current value string
SetCompact func (m *MetricCard) SetCompact(compact bool) *MetricCard SetCompact enables compact single-line mode
SetLabel func (m *MetricCard) SetLabel(label string) *MetricCard SetLabel sets the metric label
SetNumericValue func (m *MetricCard) SetNumericValue(value float64, format string) *MetricCard SetNumericValue sets value from a number with formatting
SetShowBorder func (m *MetricCard) SetShowBorder(show bool) *MetricCard SetShowBorder enables/disables the card border
SetShowSpark func (m *MetricCard) SetShowSpark(show bool) *MetricCard SetShowSpark enables/disables sparkline
SetSparkline func (m *MetricCard) SetSparkline(data []float64) *MetricCard SetSparkline sets sparkline data
SetSparklineMax func (m *MetricCard) SetSparklineMax(max float64) *MetricCard SetSparklineMax sets the max value for sparkline scaling
SetThresholds func (m *MetricCard) SetThresholds(warning, error float64, invert bool) *MetricCard SetThresholds sets warning/error thresholds for value coloring
SetTrend func (m *MetricCard) SetTrend(trend Trend, value string, good bool) *MetricCard SetTrend sets the trend indicator
SetUnit func (m *MetricCard) SetUnit(unit string) *MetricCard SetUnit sets the unit suffix
SetValue func (m *MetricCard) SetValue(value string) *MetricCard SetValue sets the displayed value

Types

type Trend Trend indicates the direction of a metric change. Use TrendUp/TrendDown for positive/negative change and TrendNeutral when there is no meaningful direction.
ConstantDescription
TrendNeutral
TrendUp
TrendDown