#
Pie Charts
This script utilizes the ApexPainter
class from the apexify.js
library to generate customizable pie charts.
#
Usage
- Import the
ApexPainter
class from theapexify.js
library:
const { ApexPainter } = require('apexify.js');
import { ApexPainter } from 'apexify.js';
2.Create an instance of the ApexPainter
class:
const painter = new ApexPainter();
3.Define options for the pie chart:
const data = {
data: [
{ label: 'Category A', color: '#ff5733', value: 30, key: 'A' },
{ label: 'Category B', color: '#33ff57', value: 20, key: 'B' },
{ label: 'Category C', color: '#5733ff', value: 25, key: 'C' },
{ label: 'Category D', color: '#ffff33', value: 15, key: 'D' },
{ label: 'Category E', color: '#33ffff', value: 10, key: 'E' }
],
pieConfig: {
pieData: {
x: -150,
y: 0,
boxes: {
colors: 'blue',
labelColor: 'black',
fontSize: 13,
labelDistance: 60,
width: 30,
height: 40
},
radius: 100,
},
stroke: {
color: 'white',
size: 2
},
title: {
text: 'Pie Chart',
color: 'black',
fontSize: 24,
x: -20,
y: -170
},
keyBox: {
bgcolor: '#ffffff',
width: 300,
height: 300,
radius: 20,
x: 800,
y: 50,
content: {
keyTitle: {
text: `Keys`,
fonstSize: 20,
x: 20,
y: 30,
},
keys: {
x: 20,
y: 30,
fontSize: 14,
}
}
},
canvas: {
width: 1200,
height: 400,
bgcolor: 'gray'
}
}
};
4.Generate the pie chart:
const chartBuffer = await painter.createChart(data, { chartType: 'pie', chartNumber: 1 });
console.log(chartBuffer); // Returns a buffer image.