Skip to content
LIBRARYCharts

Chart ​

Added in alpha.11

Included in Mavis 0.1.0-alpha.11 for Vue + Vite, Nuxt and NativeScript iOS/Android. Keep core and renderers on the same version.

Web preview
Open example ↗
vue
<MChart
  v-model="selection"
  v-model:hiddenSeries="hidden"
  :categories="days"
  :series="series"
  label="Activity"
  type="line"
/>
PropTypeDefaultDescription
categories / seriesreadonly ChartCategory[] / readonly ChartSeries[]requiredStable keys and labels; each series has one finite number or null per category.
type / heightline or bar / numberline / 240Plot type and height (120–800 px/DIP). Up to 100 categories and 8 series.
domainreadonly [number, number]automaticIncreasing finite bounds containing all values. Automatic domain includes zero.
modelValue / hiddenSeriesChartSelection or null / readonly ChoiceValue[]null / []Selection by { category, series } key and controlled legend visibility.
formatValue / showDatafunction / booleanstring / falseFormatting callback and initial textual data expansion.
animatedbooleantrueEntrance, data changes and emphasis with Jolt. false draws the finished chart.
label / description / categoryLabel / seriesLabelstringsee sourceHeading, context and accessible selection labels.
showDataLabel / hideDataLabel / emptyLabel / missingLabel / clearLabelstringEnglish labelsLocalizable actions and empty/missing states.

Categorical line and grouped bar charts share the same normalized geometry. Null creates a gap, never an invented zero. Negative values share a zero baseline; hiding a series keeps the domain stable. Web uses SVG; native uses bounded native shapes, without a WebView. Tap/click chooses a nearby series, and labelled selectors provide an alternative on every platform. Show data exposes all values, including hidden series. Values move between data sets by identity; axes do not interpolate. Colors are six-digit hex or theme defaults; color is supplemented by labels and textual values. This first version does not implement time axes, zoom, stacking, financial charts or streaming-scale datasets.

Motion ​

The first time a chart is on screen, lines draw themselves from left to right with each point appearing as the line reaches it, and bars grow from the baseline one day after another. It happens once per chart: new data, a resize, a theme change or a hidden series never replay it, and switching between lines and bars redraws only the new marks. A chart mounted below the fold waits until it is scrolled into view; server-rendered charts already on screen stay as they are.

Pointing at a point or bar brings its series forward: the line gets heavier, the point grows and the other series step back. On touch, a tap selects as before and the selection gets the same emphasis. The summary under the plot rolls up toward a larger value and down toward a smaller one, while its text and announcement change at once. Under reduced motion the chart is drawn complete and emphasis changes without travel.

Events: update:modelValue(ChartSelection or null), update:hiddenSeries(ChoiceValue[]).

vue
<script setup lang="ts">
import { computed, ref } from 'vue'
import { useCatalogLocale } from '../locale'
import type { ChartSelection, ChartSeries, ChoiceValue } from '@getcortexlabs/mavis-core'
const props = defineProps<{ lang?: 'en' | 'pt' }>()
const { locale } = useCatalogLocale(() => props.lang)
const pt = computed(() => (props.lang ?? locale.value) === 'pt')
const t = (en: string, br: string) => (pt.value ? br : en)
const selection = ref<ChartSelection | null>(null)
const hidden = ref<ChoiceValue[]>([])
const mode = ref<ChoiceValue>('line')
const nextWeek = ref(false)
const animated = ref(true)
const categories = computed(() =>
  (pt.value
    ? ['Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sáb', 'Dom']
    : ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
  ).map((label, index) => ({ key: index, label })),
)
const series = computed<ChartSeries[]>(() => [
  {
    key: 'visits',
    label: t('Visits', 'Visitas'),
    values: nextWeek.value ? [32, 44, 38, 64, 58, 72, 89] : [18, 32, 25, 48, 39, 68, 57],
  },
  {
    key: 'saves',
    label: t('Saves', 'Salvos'),
    values: nextWeek.value ? [16, 28, 20, 42, 30, 54, 62] : [8, 18, null, 27, 23, 42, 38],
  },
])
</script>

<template>
  <MCard padding="lg" gap="lg">
    <MRow justify="between" gap="sm" wrap
      ><MText
        :text="t('A good week, in perspective.', 'Uma boa semana, em perspectiva.')"
        variant="title"
        :shrink="1" /><MBadge text="+18.6%" tone="success"
    /></MRow>
    <MSegmentedControl
      v-model="mode"
      :options="[
        { value: 'line', label: t('Lines', 'Linhas') },
        { value: 'bar', label: t('Bars', 'Barras') },
      ]"
      :label="t('Chart style', 'Estilo do gráfico')"
    />
    <MChart
      v-model="selection"
      v-model:hiddenSeries="hidden"
      :type="mode === 'bar' ? 'bar' : 'line'"
      :categories="categories"
      :series="series"
      :height="200"
      :label="t('Your work is finding its people.', 'Seu trabalho encontra seu público.')"
      :description="
        t(
          'Seven days of curiosity. Select a day to look closer.',
          'Sete dias de curiosidade. Escolha um dia para ver de perto.',
        )
      "
      :categoryLabel="t('Day', 'Dia')"
      :seriesLabel="t('Metric', 'Métrica')"
      :showDataLabel="t('Show data', 'Mostrar dados')"
      :hideDataLabel="t('Hide data', 'Ocultar dados')"
      :clearLabel="t('Clear selection', 'Limpar seleção')"
      :missingLabel="t('No value', 'Sem valor')"
      :emptyLabel="t('No chart data', 'Sem dados no gráfico')"
      :animated="animated"
    />
    <MRow justify="between" align="center" gap="sm" wrap>
      <MButton
        :text="t('Another week', 'Outra semana')"
        icon="arrow-right"
        variant="ghost"
        @click="nextWeek = !nextWeek"
      />
      <MSwitch v-model="animated" :label="t('Animate', 'Animar')" />
    </MRow>
    <MText
      id="chart-value"
      :text="selection ? `${selection.category}/${selection.series}` : '—'"
      variant="caption"
      tone="muted"
    />
  </MCard>
</template>

Desktop ​

On the Mac and on Windows the chart draws its grid, lines, bars and points as native vector shapes from the same geometry as the other platforms. The plot is one control: the arrow keys move between points and announce each one, Return selects it, moving the focus elsewhere clears the point the keys reached, and the pointer shows the values of a category in a tooltip above the plot. It fades in once instead of drawing its lines, a change of data is drawn at once, and categoryLabel and seriesLabel have no effect because there are no selectors; see Desktop components.

Components for NativeScript and Web. Starting with Vue.