x4js gallery

TickLine

A tiny chart in svg, bars or a line, to show a trend in a cell or a status bar.

import { TickLine, Color } from "x4js"

Bars

A small bar chart of values between min and max (0 and 100 by default), with a tooltip on each bar.

export function bars( ) {
	return new TickLine( {
		type: "bars",
		width: 300,
		height: 60,
		values: [ 20, 35, 30, 60, 75, 50, 40, 65, 90, 70, 55, 45 ],
		color: new Color( "#569cd6" ),
		display: { tooltips: true },
	} );
}
.x4tickline {
	border: 1px solid var( --border );
}

Line

A line through the values, an axis at 0 when min is below it.

export function line( ) {
	return new TickLine( {
		type: "line",
		width: 300,
		height: 80,
		min: -50,
		max: 50,
		values: [ -10, 5, 20, 15, -25, -40, -5, 30, 45, 10 ],
		color: new Color( "#e8590c" ),
		display: { axis: true },
	} );
}

Live

setValues gives new values (and a new range): a CPU meter fed each second while it runs.

export function live( ) {
	const values = [ 40, 55, 30, 70, 60 ];
	const label = new Label( { text: "" } );
	const tick = new TickLine( { type: "bars", width: 300, height: 60, values, color: new Color( "#2f9e44" ) } );

	return new HBox( { content: [
		tick,
		new VBox( { content: [
			new Button( { label: "Start", click: ( ) => {
				tick.setInterval( "feed", 1000, ( ) => {
					values.push( Math.round( Math.random( ) * 100 ) );
					if( values.length > 30 ) {
						values.shift( );
					}
					tick.setValues( values );
					label.setText( `${values[values.length - 1]} %` );
				} );
			} } ),
			new Button( { label: "Stop", cls: "outline", click: ( ) => tick.clearInterval( "feed" ) } ),
		] } ),
		label,
	] } );
}

For an assistant: llms.txt, llms-full.txt.