MDK Logo

Chart components

Data visualization components for mining metrics

Chart components

Chart components for visualizing time-series data, metrics, and statistics. Built on Chart.js and Lightweight Charts.

Bar chart

The BarChart component renders a bar/column chart with gradient fills, stacking, and data labels. Built on Chart.js.

Import

import { BarChart } from '@mdk/core'

Props

PropTypeDefaultDescription
dataChartDatanoneRequired: Chart.js data object
optionsChartOptionsnoneChart.js options (merged with defaults)
isStackedbooleanfalseStack bars on top of each other
isHorizontalbooleanfalseRender bars horizontally
showLegendbooleantrueShow Chart.js legend
legendPosition'top' | 'right' | 'bottom' | 'left''top'Legend position
legendAlign'start' | 'center' | 'end''start'Legend alignment
showDataLabelsbooleanfalseShow values above bars
formatYLabelfunctionnoneFormat Y-axis tick labels
formatDataLabelfunctionnoneFormat data label values
tooltipChartTooltipConfignoneCustom HTML tooltip config
heightnumber300Chart height in pixels

Basic usage

const data = {
  labels: ['Jan', 'Feb', 'Mar', 'Apr'],
  datasets: [
    {
      label: 'Hashrate (TH/s)',
      data: [120, 150, 180, 200],
      backgroundColor: '#72F59E',
    },
  ],
}

<BarChart data={data} height={300} />

Stacked bar chart

const data = {
  labels: ['Site A', 'Site B', 'Site C'],
  datasets: [
    { label: 'Online', data: [100, 80, 120], backgroundColor: '#72F59E' },
    { label: 'Offline', data: [10, 20, 5], backgroundColor: '#FF6B6B' },
  ],
}

<BarChart data={data} isStacked />

Horizontal bar chart

<BarChart
  data={data}
  isHorizontal
  formatYLabel={(value) => `${value} TH/s`}
/>

With data labels

<BarChart
  data={data}
  showDataLabels
  formatDataLabel={(value) => `${value.toFixed(1)}%`}
/>

Line chart

The LineChart component renders a time-series line chart built on Lightweight Charts for high-performance rendering.

Import

import { LineChart } from '@mdk/core'

Props

PropTypeDefaultDescription
dataLineDataset[]noneRequired: Array of line datasets
timelinestringnoneTimeline identifier
heightnumber240Chart height in pixels
backgroundColorstringnoneChart background color
unitstring''Unit label for values
beginAtZerobooleanfalseStart Y-axis at zero
showPointMarkersbooleanfalseShow data point markers
yTicksFormatterfunctionnoneFormat Y-axis ticks
priceFormatterfunctionnoneFormat tooltip values
customLabelfunctionnoneCustom tooltip label
showDateInTooltipbooleanfalseShow date in tooltip
uniformDistributionbooleanfalseUniform time distribution

Basic usage

const data = [
  {
    name: 'Hashrate',
    color: '#72F59E',
    data: [
      { time: 1704067200, value: 150 },
      { time: 1704153600, value: 155 },
      { time: 1704240000, value: 160 },
    ],
  },
]

<LineChart data={data} height={300} unit="TH/s" />

Multiple lines

const data = [
  {
    name: 'Hashrate',
    color: '#72F59E',
    data: hashrateData,
  },
  {
    name: 'Target',
    color: '#FFD700',
    data: targetData,
  },
]

<LineChart data={data} showPointMarkers beginAtZero />

Area chart

The AreaChart component renders a filled area chart for cumulative or range data.

Import

import { AreaChart } from '@mdk/core'

Basic usage

const data = {
  labels: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'],
  datasets: [
    {
      label: 'Revenue',
      data: [100, 120, 115, 134, 168],
      fill: true,
      backgroundColor: 'rgba(114, 245, 158, 0.2)',
      borderColor: '#72F59E',
    },
  ],
}

<AreaChart data={data} />

Doughnut chart

The DoughnutChart component renders a doughnut/pie chart for proportional data.

Import

import { DoughnutChart } from '@mdk/core'

Basic usage

const data = {
  labels: ['Online', 'Offline', 'Maintenance'],
  datasets: [
    {
      data: [85, 10, 5],
      backgroundColor: ['#72F59E', '#FF6B6B', '#FFD700'],
    },
  ],
}

<DoughnutChart data={data} />

Gauge chart

The GaugeChart component renders a gauge/meter visualization for single values.

Import

import { GaugeChart } from '@mdk/core'

Basic usage

<GaugeChart
  value={75}
  max={100}
  label="Efficiency"
  unit="%"
/>

Chart container

The ChartContainer component is a wrapper for charts with loading and empty states.

Import

import { ChartContainer } from '@mdk/core'

Basic usage

<ChartContainer loading={isLoading} empty={data.length === 0}>
  <BarChart data={data} />
</ChartContainer>

The ChartStatsFooter component displays statistics below charts.

Import

import { ChartStatsFooter } from '@mdk/core'

Basic usage

<ChartStatsFooter
  stats={[
    { label: 'Min', value: '120 TH/s' },
    { label: 'Max', value: '180 TH/s' },
    { label: 'Avg', value: '150 TH/s' },
  ]}
/>

Detail legend

The DetailLegend component renders a detailed chart legend with values.

Import

import { DetailLegend } from '@mdk/core'

Basic usage

<DetailLegend
  items={[
    { label: 'Online', value: 85, color: '#72F59E' },
    { label: 'Offline', value: 15, color: '#FF6B6B' },
  ]}
/>

Chart utilities

The package exports utilities for building chart configurations:

import {
  defaultChartOptions,
  defaultChartColors,
  buildBarChartData,
  buildBarChartOptions,
  buildChartTooltip,
  computeStats,
} from '@mdk/core'

On this page