Percent

Type class

A relative value in percent, such as 50% of a container's width.

Create one with am5.percent(50) or new am5.Percent(50). For 0%, 50% and 100% there are ready-made am5.p0, am5.p50 and am5.p100.

Sources

Percent can be used (imported) via one of the following packages.

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

// Create Percent
am5.Percent.new(root, {
  // ... config if applicable
});
<!-- Load Percent -->
<script src="index.js"></script>

<script>
// Create Percent
am5.Percent.new(root, {
  // ... config if applicable
});
</script>

Inheritance

Percent does not extend any other symbol.

Percent is not extended by any other symbol.

Settings

Percent does not have any settings.

Private settings

Percent does not have any private settings.

Properties

percent
#

Type number

The value in percent: 50 for 50%.

@readonly

value
#

Type number

The value as a fraction: 1 for 100%, 0.5 for 50%. Multiply by it to take a share of another value:

let value = 256;
let percent = am5.percent(50);
console.log(value * percent.value); // outputs 128
var value = 256;
var percent = am5.percent(50);
console.log(value * percent.value); // outputs 128

The same with the am5.p50 shortcut:

let value = 256;
let percent = am5.p50;
console.log(value * percent.value); // outputs 128
var value = 256;
var percent = am5.p50;
console.log(value * percent.value); // outputs 128

@readonly

Methods

constructor(

percent: number

)

#

Returns Percent

Creates a percent value.

interpolate(

min: number,
max: number

)

#

Returns number

Returns the number this percent of the way from min to max.

normalize(

percent: Percent | number,
min: number,
max: number

)

#

Static

Returns Percent

Returns where percent falls between min and max as a Percent, from 0% to 100%. A Percent is returned as it is.

toString()

#

Returns string

Returns the value as a string, such as "50%".

Events

Percent does not have any events.