Skip to main content
The Percent class represents a relative value (percentage) in amCharts 5. It is used throughout the library for properties that accept percentage values.

Creating Percent Objects

percent()

function percent(value: number): Percent
Converts numeric percent value to a proper Percent object.
value
number
required
Percent value (e.g., 80 for 80%)
return
Percent
A Percent object
Example:
import * as am5 from "@amcharts/amcharts5";

pieSeries.set("radius", am5.percent(80));
column.set("width", am5.percent(50));

Shortcuts

For common percentage values, amCharts 5 provides convenient shortcuts:

p0

const p0: Percent
A shortcut for percent(0) (0%).

p50

const p50: Percent
A shortcut for percent(50) (50%).

p100

const p100: Percent
A shortcut for percent(100) (100%). Example:
import * as am5 from "@amcharts/amcharts5";

series.set("fillOpacity", am5.p50); // 50% opacity
container.set("width", am5.p100); // 100% width

Percent Class

Constructor

new Percent(percent: number)
Creates a new Percent object.
percent
number
required
Percent value (e.g., 50 for 50%)
Example:
const halfWidth = new am5.Percent(50);

Properties

value

get value(): number
value
number
Relative value where 100% = 1, 50% = 0.5, etc. This is useful to apply transformations to other values.
Example:
let totalValue = 256;
let percent = am5.p50;
console.log(totalValue * percent.value); // outputs 128

percent

get percent(): number
percent
number
Value in percent (e.g., 50 for 50%).
Example:
let p = am5.percent(75);
console.log(p.percent); // outputs 75

Methods

toString()

toString(): string
Returns string representation of the percent value.
return
string
String representation (e.g., “50%”)
Example:
let p = am5.percent(80);
console.log(p.toString()); // "80%"

interpolate()

interpolate(min: number, max: number): number
Calculates the interpolated value between min and max based on the percent.
min
number
required
Minimum value
max
number
required
Maximum value
return
number
Interpolated value
Example:
let p = am5.percent(50);
let value = p.interpolate(0, 100); // returns 50
let value2 = p.interpolate(100, 200); // returns 150

Static Methods

Percent.normalize()

static normalize(
  percent: Percent | number,
  min: number,
  max: number
): Percent
Normalizes a value to a Percent object within a given range. If a Percent is passed, it returns it as-is. If a number is passed, it normalizes it to a percentage within the min-max range.
percent
Percent | number
required
Value to normalize
min
number
required
Minimum value of the range
max
number
required
Maximum value of the range
return
Percent
Normalized Percent object
Example:
// Convert 150 to a percentage within 100-200 range
let p = am5.Percent.normalize(150, 100, 200); // 50%

// Pass through existing Percent
let p2 = am5.Percent.normalize(am5.p50, 0, 100); // 50%

Utility Functions

isPercent()

function isPercent(value: any): boolean
Checks if value is a Percent object.
value
any
required
Value to check
return
boolean
True if value is a Percent object
Example:
let p = am5.percent(50);
console.log(am5.isPercent(p)); // true
console.log(am5.isPercent(50)); // false

Usage Examples

Setting Element Dimensions

import * as am5 from "@amcharts/amcharts5";

// Set a column to be 80% of available width
column.set("width", am5.percent(80));

// Set height to 100%
container.set("height", am5.p100);

Positioning Elements

// Position label at 50% from the left
label.set("x", am5.p50);
label.set("centerX", am5.p50);

// Position at bottom right corner
element.set("x", am5.p100);
element.set("y", am5.p100);

Calculating Values

let width = 500;
let halfWidth = width * am5.p50.value; // 250

let customPercent = am5.percent(75);
let threeQuarters = width * customPercent.value; // 375

Build docs developers (and LLMs) love