JavaScript Pyramid Chart

Pyramid Chart is a chart used to show statistical graphic. The Pyramid chart is divided into slices, with each slice illustrating the numerical portion of the whole Pyramid. Each slice's size (usually depicted as the slice's relative height from the Pyramid) is proportional to its quantity.

The chart can be created with a simple line of code.

// Create a new Pyramid Chart.
const pyramid = lightningChart().Pyramid()

The Pyramid Chart has two types for displaying the labels for each slice; The slices can be placed either on top of each slice by using the LabelsInsideSlices type, or they can be placed on both sides of the Chart by using LabelsOnSides type. The type must be given to the Chart as a parameter when creating it.
By default, the LabelsOnSides type is used.

// Create a new Pyramid Chart and pass the type to use when placing labels.
const pyramid = lightningChart().Pyramid({
    type: PyramidChartTypes.LabelsOnSides,
})

After creating the Pyramid Chart, we can populate it by adding slices to it.
The slice should always get a name and value as parameters.

You can alternatively add multiple slices as an array of objects containing a name and a value for each slice.

// Add a single slice to populate the Pyramid.
pyramid.addSlice('Planning', 100)

// Add multiple slices to populate the Pyramid.
pyramid.addSlices([
    {
        name: 'Slice1',
        value: 45,
    },
    {
        name: 'Slice2',
        value: 83,
    },
    {
        name: 'Slice3',
        value: 19,
    },
])

You can modify how the Pyramid and its slices are drawn through the Pyramid Chart's API.

// Set the width of the Pyramid's bottom edge. This value can be from 0 to 100 (in percents).
pyramid.setNeckWidth(80)

// Set the gap between each of the slices. This value can be between 0 to 20 pixels.
pyramid.setSliceGap(5)

// If the labels are set to be placed on the side of the Pyramid,
// we can determine the side here as well.
pyramid.setLabelSide(PyramidLabelSide.Right)

The Slices can be styled using the Pyramid Chart's API.

// Create a palette of Solid FillStyles to use with the Pyramid slices.
const palette = SolidFillPalette(ColorPalettes.warm, data.length)
// Set the palette used for coloring each of the slices.
pyramid.setSliceFillStyle(palette)

The labels for all slices can be formatted in different ways.

// Set the label formatting to show the slice's name and the relative value
// (size of the slice as percentage).
pyramid.setLabelFormatter(SliceLabelFormatters.NamePlusRelativeValue)

The lines connecting each slice to its label can be modified.

// Set the style used with all connector lines.
pyramid.setLabelConnectorStyle(
    new SolidLine({
        thickness: 3,
        fillStyle: new SolidFill({ color: ColorRGBA(100, 150, 195) }),
    }),
)