Skip to main content

Function: race()

race(data, container?, options?): Promise<Race>

Creates a racing bar chart and returns its API object.

This is the main function that generates the racing bar chart. It accepts data as an array, a Promise, or a URL to a data file (JSON, CSV, TSV, XML), mounts the chart into the specified container, and returns a Race object for runtime interaction.

Parameters

data: string | Data[] | Promise<Data[]> | WideData[] | Promise<WideData[]>

The chart data. Accepts an array of Data (long format) or WideData (wide format) objects, a Promise resolving to one of the above, or a URL string pointing to a data file (the dataType option controls parsing).

container?: string | HTMLElement

The DOM element or CSS selector to mount the chart into. If omitted, a new <div> is appended to <body>. Existing content inside the container is cleared.

options?: Partial<Options> = {}

Partial configuration options. See Options for all available settings.

Returns

Promise<Race>

A Promise that resolves to the Race API object for controlling the chart.

Example

import { race } from 'racing-bars';
const racer = await race('/data/population.csv', '#race', {
title: 'World Population',
dataType: 'csv',
});

See

https://racing-bars.hatemhosny.dev/documentation/api

Defined in

lib/race.ts:42