CxJS

TimeAxis

import { TimeAxis } from 'cx/charts'; Copied

The TimeAxis component maps date/time data along the horizontal or vertical axis of a chart. It automatically selects appropriate tick intervals and label formats based on the time range being displayed.

This example shows monthly data over two years using a column graph. The axis automatically formats labels to show months and years.

<div controller={PageController}>
  <Svg style="width: 500px; height: 300px; border: 1px dashed #ddd">
    <Chart
      margin="60 20 40 60"
      axes={{
        x: <TimeAxis />,
        y: <NumericAxis vertical />,
      }}
    >
      <Rectangle fill="white" />
      <Gridlines />
      <ColumnGraph
        data={m.data}
        size={30 * 24 * 60 * 60 * 1000}
        offset={15 * 24 * 60 * 60 * 1000}
        xField="date"
        yField="value"
        colorIndex={0}
      />
    </Chart>
  </Svg>
</div>

Configuration

PropertyTypeDescription
mindateMinimum value.
maxdateMaximum value.
verticalbooleanSet to true for a vertical (Y) axis.
secondarybooleanSet to true to position the axis on the opposite side.
invertedbooleanSet to true to invert the axis direction.
snapToTicksnumberRange alignment: 0 = lowest ticks (default), 1 = medium ticks, 2 = major ticks.
formatstringLabel format override. If not set, format is selected based on the time range.
deadZonenumberSize of a zone reserved for labels at both ends of the axis.
upperDeadZonenumberSize of a zone reserved for labels near the upper end of the axis.
lowerDeadZonenumberSize of a zone reserved for labels near the lower end of the axis.