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 })