When adding charts via slide.addChart, follow these data and configuration rules:
General Chart Rules
- Axis Labels: For most charts, you must provide
showCatAxisTitle: true and catAxisTitle (category) along with showValAxisTitle: true and valAxisTitle (value). - Colors: Use hex colors without the
# prefix. Use chartColors array to define the palette. - Time Series Granularity:
< 30 days: Use daily grouping.30-365 days: Use monthly grouping.> 365 days: Use yearly grouping.
Chart Types
Bar/Line Charts
Use a single series with a labels array for simple charts. For multiple series, provide an array of objects, each with its own name, labels, and values.
Pie Charts
CRITICAL: Pie charts require a single data series. All categories must be in one labels array and all values in one values array.
Scatter Charts
IMPORTANT: The data format is unique. The first series must contain the X-axis values. Subsequent series contain only the Y-values.
// CORRECT: Single series Bar Chart
slide.addChart(pptx.charts.BAR, [{
name: "Sales 2024",
labels: ["Q1", "Q2", "Q3", "Q4"],
values: [4500, 5500, 6200, 7100]
}], {
...placeholders[0],
barDir: 'col',
showTitle: true,
title: 'Quarterly Sales',
showLegend: false,
showCatAxisTitle: true,
catAxisTitle: 'Quarter',
showValAxisTitle: true,
valAxisTitle: 'Sales ($000s)',
chartColors: ["4472C4"]
});
// Scatter Chart Data Format
const data1 = [{ x: 10, y: 20 }, { x: 15, y: 25 }];
const allXValues = [10, 15];
slide.addChart(pptx.charts.SCATTER, [
{ name: 'X-Axis', values: allXValues },
{ name: 'Series 1', values: [20, 25] }
], { x: 1, y: 1, w: 8, h: 4 });
// Pie Chart (Single Series Required)
slide.addChart(pptx.charts.PIE, [{
name: "Market Share",
labels: ["Product A", "Product B", "Other"],
values: [35, 45, 20]
}], {
x: 2, y: 1, w: 6, h: 4,
showPercent: true
});