Axis
Basic configuration
The Axis component has been designed to work together with XY Container. The minimal Axis configuration looks like:
- React
- Angular
- Svelte
- Vue
- Solid
- TypeScript
<VisAxis type="x"/>
<vis-axis type="x"></vis-axis>
<VisAxis type="x"/>
<VisAxis type="x" />
<VisAxis type="x"/>
const axis = new Axis<DataRecord>({ type: "x" })
Axis Types
Axis supports two AxisType properties to bind to your data: AxisType.X and AxisType.Y. You can also simply provide the string "x" or "y".
AxisType.X
- React
- Angular
- Svelte
- Vue
- Solid
- TypeScript
<VisAxis type="x"/>
<vis-axis type="x"></vis-axis>
<VisAxis type="x"/>
<VisAxis type="x" />
<VisAxis type="x"/>
const axis = new Axis<DataRecord>({ type: "x" })
AxisType.Y
- React
- Angular
- Svelte
- Vue
- Solid
- TypeScript
<VisAxis type="y"/>
<vis-axis type="y"></vis-axis>
<VisAxis type="y"/>
<VisAxis type="y" />
<VisAxis type="y"/>
const axis = new Axis<DataRecord>({ type: "y" })
Axis Position
You can change the position of your axis with a Position type or a string equivalent: "top", "right", "bottom", or "left".
- React
- Angular
- Svelte
- Vue
- Solid
- TypeScript
<VisXYContainer data={data}>
<VisAxis type="y" position="right" label="Y"/>
<VisAxis type="x" position="top" label="X"/>
</VisXYContainer>
<vis-xy-container [data]="data">
<vis-axis type="y" position="right" label="Y"></vis-axis>
<vis-axis type="x" position="top" label="X"></vis-axis>
</vis-xy-container>
<VisXYContainer {data}>
<VisAxis type="y" position="right" label="Y"/>
<VisAxis type="x" position="top" label="X"/>
</VisXYContainer>
<VisXYContainer :data="data">
<VisAxis type="y" position="right" label="Y" />
<VisAxis type="x" position="top" label="X" />
</VisXYContainer>
<VisXYContainer data={data}>
<VisAxis type="y" position="right" label="Y"/>
<VisAxis type="x" position="top" label="X"/>
</VisXYContainer>
const container = new XYContainer<DataRecord>(node, {
yAxis: new Axis({ type: "y", position: "right", label: "Y" }),
xAxis: new Axis({ type: "x", position: "top", label: "X" })
}, data)
Note: An X Axis can only accept the values Position.Bottom (default) and Position.Top and a Y Axis can only accept Position.Left (default) and Position.Right.
The default will be used in the case of an invalid position argument.
Labeling
Axis Label
You can provide a string to label your axes with the label property:
- React
- Angular
- Svelte
- Vue
- Solid
- TypeScript
<VisAxis type="x" label="Label"/>
<vis-axis type="x" label="Label"></vis-axis>
<VisAxis type="x" label="Label"/>
<VisAxis type="x" label="Label" />
<VisAxis type="x" label="Label"/>
const axis = new Axis<DataRecord>({ type: "x", label: "Label" })
Label Font Size
Change the label size (in pixels) with the labelFontSize property.
- React
- Angular
- Svelte
- Vue
- Solid
- TypeScript
<VisAxis type="x" label="Label" labelFontSize={30}/>
<vis-axis type="x" label="Label" [labelFontSize]="30"></vis-axis>
<VisAxis type="x" label="Label" labelFontSize={30}/>
<VisAxis type="x" label="Label" :labelFontSize="30" />
<VisAxis type="x" label="Label" labelFontSize={30}/>
const axis = new Axis<DataRecord>({ type: "x", label: "Label", labelFontSize: 30 })
Label Color
Change the label color with the labelColor property.
- React
- Angular
- Svelte
- Vue
- Solid
- TypeScript
<VisAxis type="x" label="Label" labelColor="#1acb9a"/>
<vis-axis type="x" label="Label" labelColor="#1acb9a"></vis-axis>
<VisAxis type="x" label="Label" labelColor="#1acb9a"/>
<VisAxis type="x" label="Label" labelColor="#1acb9a" />
<VisAxis type="x" label="Label" labelColor="#1acb9a"/>
const axis = new Axis<DataRecord>({
type: "x",
label: "Label",
labelColor: "#1acb9a"
})
Label Margin
The spacing between the label and the axis itself can be set with the labelMargin property:
- React
- Angular
- Svelte
- Vue
- Solid
- TypeScript
<VisAxis type="x" label="Label" labelMargin={5}/>
<vis-axis type="x" label="Label" [labelMargin]="5"></vis-axis>
<VisAxis type="x" label="Label" labelMargin={5}/>
<VisAxis type="x" label="Label" :labelMargin="5" />
<VisAxis type="x" label="Label" labelMargin={5}/>
const axis = new Axis<DataRecord>({ type: "x", label: "Label", labelMargin: 5 })
Label Text Separator
When a label is too long to fit, Axis wraps it onto multiple lines (this happens when labelTextFitMode is
set to FitMode.Wrap, which is the default). You can control where the text is allowed to break by providing the
labelTextSeparator property with a string or string[] of separators. By default the label breaks on spaces, hyphens, periods and commas.
In the example below the label contains none of the default separators, so it can't wrap and overflows the axis.
Provide "/" as the separator to let it break on the slashes instead.
- React
- Angular
- Svelte
- Vue
- Solid
- TypeScript
<VisAxis
type="y"
label="Population/Density/Per/Square/Kilometer"
labelTextSeparator="/"
/>
<vis-axis
type="y"
label="Population/Density/Per/Square/Kilometer"
labelTextSeparator="/"
></vis-axis>
<VisAxis
type="y"
label="Population/Density/Per/Square/Kilometer"
labelTextSeparator="/"
/>
<VisAxis
type="y"
label="Population/Density/Per/Square/Kilometer"
labelTextSeparator="/"
/>
<VisAxis
type="y"
label="Population/Density/Per/Square/Kilometer"
labelTextSeparator="/"
/>
const axis = new Axis<DataRecord>({
type: "y",
label: "Population/Density/Per/Square/Kilometer",
labelTextSeparator: "/"
})
Grid Line
You can enable or disable the visibility of the Axis grid line with the gridLine property.
- React
- Angular
- Svelte
- Vue
- Solid
- TypeScript
<VisAxis type="x" gridLine={true}/>
<vis-axis type="x" [gridLine]="true"></vis-axis>
<VisAxis type="x" gridLine={true}/>
<VisAxis type="x" :gridLine="true" />
<VisAxis type="x" gridLine={true}/>
const axis = new Axis<DataRecord>({ type: "x", gridLine: true })
Axis Domain Line
You can enable or disable the visibility of the axis domain line with the domainLine property.
- React
- Angular
- Svelte
- Vue
- Solid
- TypeScript
<VisAxis type="x" label="Label" domainLine={true}/>
<vis-axis type="x" label="Label" [domainLine]="true"></vis-axis>
<VisAxis type="x" label="Label" domainLine={true}/>
<VisAxis type="x" label="Label" :domainLine="true" />
<VisAxis type="x" label="Label" domainLine={true}/>
const axis = new Axis<DataRecord>({ type: "x", label: "Label", domainLine: true })
Tick Configuration
The Axis component supports a wide variety of tick customization options
Tick Line
You can remove tick labels from your axis by setting the tickLine property to false:
- React
- Angular
- Svelte
- Vue
- Solid
- TypeScript
<VisAxis type="x" tickLine={undefined}/>
<vis-axis type="x" [tickLine]="undefined"></vis-axis>
<VisAxis type="x" tickLine={undefined}/>
<VisAxis type="x" :tickLine="undefined" />
<VisAxis type="x" tickLine={undefined}/>
const axis = new Axis<DataRecord>({ type: "x", tickLine: undefined })
Tick Size
Control the length of the tick marks (in pixels) with the tickSize property. It accepts a single number, which applies to both inner and outer ticks, or a [innerTickSize, outerTickSize] tuple to set them independently. The default value is 6.
- React
- Angular
- Svelte
- Vue
- Solid
- TypeScript
<VisAxis type="x" tickSize={6}/>
<vis-axis type="x" [tickSize]="6"></vis-axis>
<VisAxis type="x" tickSize={6}/>
<VisAxis type="x" :tickSize="6" />
<VisAxis type="x" tickSize={6}/>
const axis = new Axis<DataRecord>({ type: "x", tickSize: 6 })
Tick Label Font Size
To change the font size for the tick labels, you provide the tickTextFontSize property with a CSS string.
- React
- Angular
- Svelte
- Vue
- Solid
- TypeScript
<VisAxis type="x" tickTextFontSize="50px"/>
<vis-axis type="x" tickTextFontSize="50px"></vis-axis>
<VisAxis type="x" tickTextFontSize="50px"/>
<VisAxis type="x" tickTextFontSize="50px" />
<VisAxis type="x" tickTextFontSize="50px"/>
const axis = new Axis<DataRecord>({ type: "x", tickTextFontSize: "50px" })
Tick Label Color
You can change the color of the tick labels with the tickTextColor property.
- React
- Angular
- Svelte
- Vue
- Solid
- TypeScript
<VisAxis type="x" tickTextColor="#1acb9a"/>
<vis-axis type="x" tickTextColor="#1acb9a"></vis-axis>
<VisAxis type="x" tickTextColor="#1acb9a"/>
<VisAxis type="x" tickTextColor="#1acb9a" />
<VisAxis type="x" tickTextColor="#1acb9a"/>
const axis = new Axis<DataRecord>({ type: "x", tickTextColor: "#1acb9a" })
Tick Label Format
You can customize how ticks are formatted using the tickFormat property and a label formatter function.
The following example uses Javascript's built-in Date formatter function toDateString().
- React
- Angular
- Svelte
- Vue
- Solid
- TypeScript
<VisAxis type="x" x={x} tickFormat={tickFormat}/>
<vis-axis type="x" [x]="x" [tickFormat]="tickFormat"></vis-axis>
<VisAxis type="x" {x} {tickFormat}/>
<VisAxis type="x" :x="x" :tickFormat="tickFormat" />
<VisAxis type="x" x={x} tickFormat={tickFormat}/>
const axis = new Axis<DataRecord>({ type: "x", x, tickFormat })
Tick Label Alignment
Change the tick's label alignment with respect to the tick marker using tickTextAlign. It accepts a constant TextAlign value (TextAlign.Left, TextAlign.Right or TextAlign.Center)
or a function for per-tick control. The function receives (tickValue, tickIndex, ticksValues, tickPosition, componentWidth, componentHeight) and should return a TextAlign value.
- React
- Angular
- Svelte
- Vue
- Solid
- TypeScript
<VisAxis type="x" tickTextAlign="right"/>
<vis-axis type="x" tickTextAlign="right"></vis-axis>
<VisAxis type="x" tickTextAlign="right"/>
<VisAxis type="x" tickTextAlign="right" />
<VisAxis type="x" tickTextAlign="right"/>
const axis = new Axis<DataRecord>({ type: "x", tickTextAlign: "right" })
Tick Label Rotation
Change the tick's label angle using tickTextAngle property with a number value. Use this variable along with tickTextAlign to make sure the tick label displays as desired.
- React
- Angular
- Svelte
- Vue
- Solid
- TypeScript
<VisAxis type="x" tickTextAlign="left" tickTextAngle={15}/>
<vis-axis
type="x"
tickTextAlign="left"
[tickTextAngle]="15"
></vis-axis>
<VisAxis type="x" tickTextAlign="left" tickTextAngle={15}/>
<VisAxis type="x" tickTextAlign="left" :tickTextAngle="15" />
<VisAxis type="x" tickTextAlign="left" tickTextAngle={15}/>
const axis = new Axis<DataRecord>({
type: "x",
tickTextAlign: "left",
tickTextAngle: 15
})
Tick Label Width
To limit the width of the tick labels (in pixels), you can use the tickTextWidth property.
- React
- Angular
- Svelte
- Vue
- Solid
- TypeScript
<VisAxis type="x" tickTextWidth={50}/>
<vis-axis type="x" [tickTextWidth]="50"></vis-axis>
<VisAxis type="x" tickTextWidth={50}/>
<VisAxis type="x" :tickTextWidth="50" />
<VisAxis type="x" tickTextWidth={50}/>
const axis = new Axis<DataRecord>({ type: "x", tickTextWidth: 50 })
Tick Label Fit Mode
Axis accepts the following values for the tickTextFitMode property: FitMode.Wrap or FitMode.Trim. This determines how the axis will
handle tick text overflow. The following example showcases the previous example using "trim" instead of "wrap".
- React
- Angular
- Svelte
- Vue
- Solid
- TypeScript
<VisAxis type="x" tickTextWidth={10} tickTextFitMode="trim"/>
<vis-axis
type="x"
[tickTextWidth]="10"
tickTextFitMode="trim"
></vis-axis>
<VisAxis type="x" tickTextWidth={10} tickTextFitMode="trim"/>
<VisAxis type="x" :tickTextWidth="10" tickTextFitMode="trim" />
<VisAxis type="x" tickTextWidth={10} tickTextFitMode="trim"/>
const axis = new Axis<DataRecord>({
type: "x",
tickTextWidth: 10,
tickTextFitMode: "trim"
})
Tick Label Trim Type
When a tick label becomes too long, and you want to trim it, you can customize the trimming method with the tickTextTrimType property.
Axis accepts a TrimMode or a string. For example, when we configure tickTextTrimType to TrimMode.Start, we can see the start of the label gets cut off instead of the middle.
- React
- Angular
- Svelte
- Vue
- Solid
- TypeScript
<VisAxis
type="x"
tickTextFitMode="trim"
tickTextWidth={30}
tickTextTrimType="start"
/>
<vis-axis
type="x"
tickTextFitMode="trim"
[tickTextWidth]="30"
tickTextTrimType="start"
></vis-axis>
<VisAxis
type="x"
tickTextFitMode="trim"
tickTextWidth={30}
tickTextTrimType="start"
/>
<VisAxis
type="x"
tickTextFitMode="trim"
:tickTextWidth="30"
tickTextTrimType="start"
/>
<VisAxis
type="x"
tickTextFitMode="trim"
tickTextWidth={30}
tickTextTrimType="start"
/>
const axis = new Axis<DataRecord>({
type: "x",
tickTextFitMode: "trim",
tickTextWidth: 30,
tickTextTrimType: "start"
})
Force Word Break
In addition, you can enable a forced word break for overflowing tick labels with the tickTextForceWordBreak property.
- React
- Angular
- Svelte
- Vue
- Solid
- TypeScript
<VisAxis type="x" tickTextWidth={10} tickTextForceWordBreak={true}/>
<vis-axis
type="x"
[tickTextWidth]="10"
[tickTextForceWordBreak]="true"
></vis-axis>
<VisAxis type="x" tickTextWidth={10} tickTextForceWordBreak={true}/>
<VisAxis type="x" :tickTextWidth="10" :tickTextForceWordBreak="true" />
<VisAxis type="x" tickTextWidth={10} tickTextForceWordBreak={true}/>
const axis = new Axis<DataRecord>({
type: "x",
tickTextWidth: 10,
tickTextForceWordBreak: true
})
Tick Label Separator
Axis accepts a string or string[] value for tickTextSeparator property. This will allow tick labels to be separated by custom values in the case of overflow.
Note: this only takes effect when FitMode.Wrap is enabled and tickTextWidth is defined.
- React
- Angular
- Svelte
- Vue
- Solid
- TypeScript
<VisAxis type="x" tickTextWidth={10} tickTextSeparator=","/>
<vis-axis
type="x"
[tickTextWidth]="10"
tickTextSeparator=","
></vis-axis>
<VisAxis type="x" tickTextWidth={10} tickTextSeparator=","/>
<VisAxis type="x" :tickTextWidth="10" tickTextSeparator="," />
<VisAxis type="x" tickTextWidth={10} tickTextSeparator=","/>
const axis = new Axis<DataRecord>({
type: "x",
tickTextWidth: 10,
tickTextSeparator: ","
})
Custom Number of Ticks
By default, the Axis component provides an optimal number of ticks displayed based on the component's size. You can alter the tick count to your liking using the numTicks property.
The specified count is only a hint, the axis can have more or fewer ticks depending on the data
- React
- Angular
- Svelte
- Vue
- Solid
- TypeScript
<VisAxis type="x" numTicks={20}/>
<vis-axis type="x" [numTicks]="20"></vis-axis>
<VisAxis type="x" numTicks={20}/>
<VisAxis type="x" :numTicks="20" />
<VisAxis type="x" numTicks={20}/>
const axis = new Axis<DataRecord>({ type: "x", numTicks: 20 })
Tick Spacing new
When numTicks is not set, the Axis derives the tick count from the component's size. For the X axis, the tickSpacing property controls that density by setting the approximate distance between ticks in pixels (default: 175). Smaller values pack in more ticks; larger values spread them out.
tickSpacing only applies to the X axis, and is ignored when numTicks is set explicitly.
- React
- Angular
- Svelte
- Vue
- Solid
- TypeScript
<VisAxis type="x" tickSpacing={175}/>
<vis-axis type="x" [tickSpacing]="175"></vis-axis>
<VisAxis type="x" tickSpacing={175}/>
<VisAxis type="x" :tickSpacing="175" />
<VisAxis type="x" tickSpacing={175}/>
const axis = new Axis<DataRecord>({ type: "x", tickSpacing: 175 })
Display Only Minimum and Maximum Ticks
Set the minMaxTicksOnly property to true if you only want to see the two end ticks on the axis.
To display the minimum and maximum ticks only when the chart width is limited (this behavior is enabled my default),
you can use the minMaxTicksOnlyWhenWidthIsLess property (defaults to 250px). This helps avoid clutter in smaller visualizations while still
providing essential information.
- React
- Angular
- Svelte
- Vue
- Solid
- TypeScript
<VisAxis type="x" minMaxTicksOnly={true}/>
<vis-axis type="x" [minMaxTicksOnly]="true"></vis-axis>
<VisAxis type="x" minMaxTicksOnly={true}/>
<VisAxis type="x" :minMaxTicksOnly="true" />
<VisAxis type="x" minMaxTicksOnly={true}/>
const axis = new Axis<DataRecord>({ type: "x", minMaxTicksOnly: true })
When using minMaxTicksOnly, you can still show grid lines by setting minMaxTicksOnlyShowGridLines to true.
- React
- Angular
- Svelte
- Vue
- Solid
- TypeScript
<VisAxis
minMaxTicksOnly={true}
type="x"
minMaxTicksOnlyShowGridLines={true}
/>
<vis-axis
[minMaxTicksOnly]="true"
type="x"
[minMaxTicksOnlyShowGridLines]="true"
></vis-axis>
<VisAxis
minMaxTicksOnly={true}
type="x"
minMaxTicksOnlyShowGridLines={true}
/>
<VisAxis
:minMaxTicksOnly="true"
type="x"
:minMaxTicksOnlyShowGridLines="true"
/>
<VisAxis
minMaxTicksOnly={true}
type="x"
minMaxTicksOnlyShowGridLines={true}
/>
const axis = new Axis<DataRecord>({
minMaxTicksOnly: true,
type: "x",
minMaxTicksOnlyShowGridLines: true
})
Set Ticks Explicitly
You can customize the ticks displayed by providing the Axis component with a number array.
The following example only shows even values for x after getting the tickValue array from a filter function.
function tickValues() {
return data.filter(d => d.x % 2 == 0)
})
- React
- Angular
- Svelte
- Vue
- Solid
- TypeScript
<VisAxis type="x" tickValues={[0,2,4,6,8]}/>
<vis-axis type="x" [tickValues]="[0,2,4,6,8]"></vis-axis>
<VisAxis type="x" tickValues={[0,2,4,6,8]}/>
<VisAxis type="x" :tickValues="[0,2,4,6,8]" />
<VisAxis type="x" tickValues={[0,2,4,6,8]}/>
const axis = new Axis<DataRecord>({ type: "x", tickValues: [0,2,4,6,8] })
Hide Overlapping Ticks
To prevent overlapping tick labels on the axis, you can use the tickTextHideOverlapping
property. When enabled, it hides any tick labels that would otherwise overlap with
one another based on a simple bounding box collision detection algorithm. This
ensures cleaner, more legible axes, particularly in cases where the available space
is limited or when displaying many ticks.
The algorithm used for detecting overlaps may not be accurate when a tickTextAngle is specified,
so results can vary depending on tick rotation.
- React
- Angular
- Svelte
- Vue
- Solid
- TypeScript
<VisAxis type="x" numTicks={15} tickTextHideOverlapping={true}/>
<vis-axis
type="x"
[numTicks]="15"
[tickTextHideOverlapping]="true"
></vis-axis>
<VisAxis type="x" numTicks={15} tickTextHideOverlapping={true}/>
<VisAxis type="x" :numTicks="15" :tickTextHideOverlapping="true" />
<VisAxis type="x" numTicks={15} tickTextHideOverlapping={true}/>
const axis = new Axis<DataRecord>({
type: "x",
numTicks: 15,
tickTextHideOverlapping: true
})
Adaptive Tick Sets new
Set tickTextAdaptiveSets to true to let the Axis pick the number of ticks automatically so that their labels never overlap. The axis measures candidate tick sets off-screen and renders the largest "nice" set that fits, degrading to sparser sets on narrower charts. Ticks left out of the fitted set still render as unlabeled tick marks, so the axis scale stays visually intact.
numTicks (or, when it's not set, the width-based default derived from tickSpacing) acts as the upper bound on the number of labeled ticks.
Toggle the checkbox below to see how enabling tickTextAdaptiveSets resolves the overlap on a dense, wide-range axis:
- React
- Angular
- Svelte
- Vue
- Solid
- TypeScript
<VisAxis type="x" numTicks={20} tickTextAdaptiveSets={true}/>
<vis-axis
type="x"
[numTicks]="20"
[tickTextAdaptiveSets]="true"
></vis-axis>
<VisAxis type="x" numTicks={20} tickTextAdaptiveSets={true}/>
<VisAxis type="x" :numTicks="20" :tickTextAdaptiveSets="true" />
<VisAxis type="x" numTicks={20} tickTextAdaptiveSets={true}/>
const axis = new Axis<DataRecord>({
type: "x",
numTicks: 20,
tickTextAdaptiveSets: true
})
When explicit tickValues are provided, the axis instead fits every-k-th subset of them (every value, then every 2nd, every 3rd, and so on), anchored at the first value so the labeled ticks stay evenly spaced.
tickTextAdaptiveSets takes over the narrow-width behavior: it disables the width-based minMaxTicksOnlyWhenWidthIsLess fallback, and has no effect when minMaxTicksOnly is enabled.
When tickTextAdaptiveSets is enabled, you don't need to also set tickTextHideOverlapping. The adaptive pass already measures label overlap and only labels the ticks that fit, so no labels overlap in the first place.
Displaying Multiple Axes
More commonly, you will want to display both an x and y axis for your graph. You can display multiple axes in an XY Container like so:
- React
- Angular
- Svelte
- Vue
- Solid
- TypeScript
<VisXYContainer data={data}>
<VisAxis type="y"/>
<VisAxis type="x"/>
</VisXYContainer>
<vis-xy-container [data]="data">
<vis-axis type="y"></vis-axis>
<vis-axis type="x"></vis-axis>
</vis-xy-container>
<VisXYContainer {data}>
<VisAxis type="y"/>
<VisAxis type="x"/>
</VisXYContainer>
<VisXYContainer :data="data">
<VisAxis type="y" />
<VisAxis type="x" />
</VisXYContainer>
<VisXYContainer data={data}>
<VisAxis type="y"/>
<VisAxis type="x"/>
</VisXYContainer>
const container = new XYContainer<DataRecord>(node, {
yAxis: new Axis({ type: "y" }),
xAxis: new Axis({ type: "x" })
}, data)
Displaying Axis with a Chart
You can include a chart within your XY Container alongside your axes like this:
- React
- Angular
- Svelte
- Vue
- Solid
- TypeScript
<VisXYContainer data={data}>
<VisAxis type="y"/>
<VisLine x={x} y={y}/>
<VisAxis type="x"/>
</VisXYContainer>
<vis-xy-container [data]="data">
<vis-axis type="y"></vis-axis>
<vis-line [x]="x" [y]="y"></vis-line>
<vis-axis type="x"></vis-axis>
</vis-xy-container>
<VisXYContainer {data}>
<VisAxis type="y"/>
<VisLine {x} {y}/>
<VisAxis type="x"/>
</VisXYContainer>
<VisXYContainer :data="data">
<VisAxis type="y" />
<VisLine :x="x" :y="y" />
<VisAxis type="x" />
</VisXYContainer>
<VisXYContainer data={data}>
<VisAxis type="y"/>
<VisLine x={x} y={y}/>
<VisAxis type="x"/>
</VisXYContainer>
const container = new XYContainer<DataRecord>(node, {
yAxis: new Axis({ type: "y" }),
components: [new Line({ x, y })],
xAxis: new Axis({ type: "x" })
}, data)
Using Axis Alone
If you use the Axis component alone, without other xy-components, you can provide an x accessor or y accessors to populate the axis values.
Consider the following example with a single axis and a data array with x values in the range 0 < x < 10:
- React
- Angular
- Svelte
- Vue
- Solid
- TypeScript
<VisAxis type="x" x={x}/>
<vis-axis type="x" [x]="x"></vis-axis>
<VisAxis type="x" {x}/>
<VisAxis type="x" :x="x" />
<VisAxis type="x" x={x}/>
const axis = new Axis<DataRecord>({ type: "x", x })
Alternatively, you can set the xDomain or yDomain property on XYContainer to set the domain of the axis:
- React
- Angular
- Svelte
- Vue
- Solid
- TypeScript
import { VisXYContainer, VisAxis } from '@unovis/react'
function Component(props) {
const data: DataRecord[] = props.data
return (
<VisXYContainer xDomain={[0,15]} data={data}>
<VisAxis type="x"/>
</VisXYContainer>
)
}
@Component({
templateUrl: 'template.html'
})
export class Component {
@Input data: DataRecord[];
}
<vis-xy-container [xDomain]="[0,15]" [data]="data">
<vis-axis type="x"></vis-axis>
</vis-xy-container>
<script lang='ts'>
import { VisXYContainer, VisAxis } from '@unovis/svelte'
export let data: DataRecord[]
</script>
<VisXYContainer xDomain={[0,15]} {data}>
<VisAxis type="x"/>
</VisXYContainer>
<script setup lang="ts">
import { VisXYContainer, VisAxis } from '@unovis/vue'
const props = defineProps<{ data: DataRecord[] }>()
</script>
<template>
<VisXYContainer :xDomain="[0,15]" :data="data">
<VisAxis type="x" />
</VisXYContainer>
</template>
import { VisXYContainer, VisAxis } from '@unovis/solid'
function Component(props) {
const data: DataRecord[] = () => props.data
return (
<VisXYContainer xDomain={[0,15]} data={data()}>
<VisAxis type="x"/>
</VisXYContainer>
)
}
import { XYContainer, Axis } from '@unovis/ts'
import { data, DataRecord } from './data'
const container = new XYContainer<DataRecord>(node, {
xDomain: [0,15],
xAxis: new Axis<DataRecord>({ type: "x" })
}, data)
Additional Styling: CSS Variables
The Axis component supports additional styling via CSS variables that you can define for your visualization container. For example:
.container {
--vis-axis-tick-label-font-size: 20px;
--vis-axis-label-color: #1acb9a;
--vis-axis-font-family: monospace;
--vis-axis-tick-label-color: #8777d9;
}
All supported CSS variables and their default values
--vis-axis-font-family: undefined;
--vis-axis-tick-color: #e8e9ef;
--vis-axis-domain-color: undefined;
--vis-axis-domain-line-dasharray: undefined;
--vis-axis-grid-color: #e8e9ef;
--vis-axis-grid-line-width: 1px;
--vis-axis-grid-line-dasharray: none;
--vis-axis-grid-opacity: 1;
--vis-axis-grid-transition: none;
--vis-axis-label-font-size: 14px;
--vis-axis-label-color: #6c778c;
--vis-axis-label-weight: 500;
--vis-axis-tick-label-color: #6c778c;
--vis-axis-tick-label-font-size: 12px;
--vis-axis-tick-label-weight: 500;
--vis-axis-tick-label-cursor: default;
--vis-axis-tick-label-text-decoration: none;
--vis-axis-tick-line-width: 1px;
--vis-axis-tick-label-hide-transition: opacity 400ms ease-in-out;
--vis-axis-domain-line-width: undefined;
--vis-dark-axis-tick-color: #6c778c;
--vis-dark-axis-domain-color: undefined;
--vis-dark-axis-tick-label-color: #e8e9ef;
--vis-dark-axis-grid-color: #6c778c;
--vis-dark-axis-label-color: #fefefe;
Events
import { Axis } from '@unovis/ts'
events = {
[Axis.selectors.tick]: {
mouseover: (d: number | Date) => {},
mouseout: (d: number | Date) => {}
}
}
- React
- Angular
- Svelte
- Vue
- Solid
- TypeScript
<VisAxis type="x" events={events}/>
<vis-axis type="x" [events]="events"></vis-axis>
<VisAxis type="x" {events}/>
<VisAxis type="x" :events="events" />
<VisAxis type="x" events={events}/>
const axis = new Axis<DataRecord>({ type: "x", events })
Component Props
| Name | Type | Description |
|---|---|---|
| * required property |