chart

This module provides functionality to create and manipulate charts using Chart.js. It includes a renderer for generating chart images and a font registration system.
Description:
  • This module provides functionality to create and manipulate charts using Chart.js. It includes a renderer for generating chart images and a font registration system.

Members

(inner, constant) DATA_URL

Description:
  • This constant represents the output type for rendering charts as a Data URL.
This constant represents the output type for rendering charts as a Data URL.

Methods

(static) registerFont(scope, filePath, options)

Description:
  • Registers a custom font from a file to be used in charts. This should be called at the application's startup or in a default_include script.
Example
chart.registerFont(fs.BOX, 'path/to/Roboto-Regular.ttf', { family: 'Roboto' });
Parameters:
Name Type Description
scope string The scope where the font file is located (fs.BOX or fs.WEB).
filePath string The path to the .ttf or .otf font file.
options object Font registration options.
Properties
Name Type Description
family string The font-family name to use in Chart.js configs (e.g., 'Roboto').
Throws:
If the font file cannot be found or registered.
Type
Error

(static) runInGBox(configuration, optionsopt) → {Promise.<(Buffer|string)>}

Description:
  • Renders a chart based on a Chart.js configuration object.
Example
const chart = require('chart');
const config = {
    type: 'bar',
    data: {
        labels: ['January', 'February', 'March'],
        datasets: [{
            label: 'Sales',
            data: [100, 200, 300]
        }]
    }
};
const imageBuffer = await chart.render(config);
// To send the image in a http response:
$g.response.send(imageBuffer, 200, 'image/png');
Parameters:
Name Type Attributes Description
configuration object A standard Chart.js configuration object (type, data, options).
options object <optional>
Optional settings for the output.
Properties
Name Type Attributes Default Description
width number <optional>
800 The width of the final image in pixels.
height number <optional>
600 The height of the final image in pixels.
output string <optional>
'buffer' The output type: 'buffer' or 'dataurl'.
Throws:
If the configuration is invalid or rendering fails.
Type
Error
Returns:
A promise that resolves with the chart image data.
Type
Promise.<(Buffer|string)>