Skip to content

Axes

Configure X and Y axes for precise control over chart labels, grid lines, and value formatting.

Axis text styling (textColor, textSize) is applied consistently on iOS and Android for all chart types that expose axes.

X-Axis Configuration

typescript
import type { XAxisConfig } from '@nstudio/ncharts';

const xAxis: XAxisConfig = {
  enabled: true,
  position: 'BOTTOM',
  drawGridLines: true,
  drawLabels: true,
  granularity: 1,
  textSize: 10,
  valueFormatter: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'],
};

X-Axis Properties

PropertyTypeDefaultDescription
enabledbooleantrueShow/hide axis
positionXAxisPosition'BOTTOM'Axis position
yOffsetnumber-Vertical offset from position
typescript
type XAxisPosition = 
  | 'TOP'
  | 'BOTTOM'
  | 'BOTH_SIDED'
  | 'TOP_INSIDE'
  | 'BOTTOM_INSIDE';

Y-Axis Configuration

Bar and line charts support dual Y-axes:

typescript
import type { YAxisConfigDual } from '@nstudio/ncharts';

const yAxis: YAxisConfigDual = {
  left: {
    enabled: true,
    drawGridLines: true,
    axisMinimum: 0,
    axisMaximum: 100,
  },
  right: {
    enabled: false,
  },
};

Y-Axis Properties

PropertyTypeDefaultDescription
enabledbooleantrueShow/hide axis
positionYAxisPosition'OUTSIDE_CHART'Label position
typescript
type YAxisPosition = 'OUTSIDE_CHART' | 'INSIDE_CHART';

Common Axis Properties

These properties apply to both X and Y axes:

Lines & Labels

PropertyTypeDefaultDescription
drawGridLinesbooleantrueShow grid lines
drawAxisLinebooleantrueShow axis line
drawLabelsbooleantrueShow labels

Text Styling

PropertyTypeDefaultDescription
textColorChartColor-Label text color
textSizenumber10Label text size
fontFamilystring-Font family
fontStylenumber-0=normal, 1=bold, 2=italic

Grid Line Styling

PropertyTypeDefaultDescription
gridColorChartColor-Grid line color
gridLineWidthnumber1Grid line width
gridDashedLineobject-Dashed grid line config
typescript
gridDashedLine: {
  lineLength: 10,
  spaceLength: 5,
  phase: 0,
}

Axis Line Styling

PropertyTypeDefaultDescription
axisLineColorChartColor-Axis line color
axisLineWidthnumber1Axis line width

Value Range

PropertyTypeDefaultDescription
axisMinimumnumber-Minimum value (auto if not set)
axisMaximumnumber-Maximum value (auto if not set)
invertedbooleanfalseInvert axis direction
spaceTopnumber10Extra space at top (%)
spaceBottomnumber10Extra space at bottom (%)

Labels

PropertyTypeDefaultDescription
labelCountnumber-Number of labels
labelCountForcebooleanfalseForce exact label count
granularitynumber1Minimum step between labels
granularityEnabledbooleanfalseEnable granularity
centerAxisLabelsbooleanfalseCenter labels between ticks
labelRotationAnglenumber0Rotation angle in degrees
avoidFirstLastClippingbooleanfalsePrevent label clipping

Value Formatters

Built-in Formatters

typescript
valueFormatter: 'largeValue'  // 1000 → 1K, 1000000 → 1M
valueFormatter: 'percent'     // 0.5 → 50%
valueFormatter: 'date'        // Uses valueFormatterPattern

Custom Labels Array

typescript
valueFormatter: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']

Date Formatting

typescript
valueFormatter: 'date',
valueFormatterPattern: 'MMM dd',  // iOS/Android date pattern

Label by X Value

typescript
valueFormatter: 'labelByXValue',
valueFormatterLabels: [
  { x: 0, label: 'Start' },
  { x: 5, label: 'Middle' },
  { x: 10, label: 'End' },
],

Limit Lines

Add reference lines to your axes:

typescript
import type { LimitLine } from '@nstudio/ncharts';

const yAxis: YAxisConfig = {
  enabled: true,
  limitLines: [
    {
      limit: 75,
      label: 'Target',
      lineColor: '#EF4444',
      lineWidth: 2,
      labelPosition: 'RIGHT_TOP',
      valueTextColor: '#EF4444',
      valueTextSize: 10,
    },
    {
      limit: 50,
      label: 'Average',
      lineColor: '#F59E0B',
      lineWidth: 1,
      lineDashLengths: [10, 5],
    },
  ],
  drawLimitLinesBehindData: true,
};

Limit Line Properties

PropertyTypeDescription
limitnumberValue on axis
labelstringLabel text
lineColorChartColorLine color
lineWidthnumberLine width
labelPositionLimitLineLabelPositionLabel position
valueTextColorChartColorLabel text color
valueTextSizenumberLabel text size
lineDashLengthsnumber[]Dash pattern
lineDashPhasenumberDash phase
typescript
type LimitLineLabelPosition = 
  | 'LEFT_TOP'
  | 'LEFT_BOTTOM'
  | 'RIGHT_TOP'
  | 'RIGHT_BOTTOM';

Y-Axis Zero Line

Highlight the zero line:

typescript
const yAxis: YAxisConfig = {
  enabled: true,
  zeroLine: {
    enabled: true,
    lineWidth: 1.5,
    lineColor: '#374151',
  },
};

Complete Example

typescript
import type { XAxisConfig, YAxisConfigDual } from '@nstudio/ncharts';

const xAxis: XAxisConfig = {
  enabled: true,
  position: 'BOTTOM',
  drawGridLines: true,
  drawAxisLine: true,
  drawLabels: true,
  gridColor: '#E5E7EB',
  gridLineWidth: 1,
  axisLineColor: '#9CA3AF',
  axisLineWidth: 1,
  textColor: '#6B7280',
  textSize: 10,
  granularity: 1,
  labelRotationAngle: -45,
  valueFormatter: ['Q1', 'Q2', 'Q3', 'Q4'],
};

const yAxis: YAxisConfigDual = {
  left: {
    enabled: true,
    position: 'OUTSIDE_CHART',
    drawGridLines: true,
    drawAxisLine: false,
    gridColor: '#E5E7EB',
    textColor: '#6B7280',
    textSize: 10,
    axisMinimum: 0,
    spaceTop: 15,
    valueFormatter: 'largeValue',
    limitLines: [
      {
        limit: 80,
        label: 'Goal',
        lineColor: '#10B981',
        lineWidth: 2,
        lineDashLengths: [8, 4],
        labelPosition: 'RIGHT_TOP',
      },
    ],
  },
  right: {
    enabled: false,
  },
};

Dual Axis Setup

For charts with two different scales:

typescript
const yAxis: YAxisConfigDual = {
  left: {
    enabled: true,
    axisMinimum: 0,
    axisMaximum: 1000000,
    textColor: '#3B82F6',
    valueFormatter: 'largeValue',
  },
  right: {
    enabled: true,
    axisMinimum: 0,
    axisMaximum: 100,
    textColor: '#10B981',
    valueFormatter: 'percent',
  },
};

Then assign datasets to the appropriate axis:

typescript
config: {
  axisDependency: 'LEFT',  // or 'RIGHT'
}

See Also