Observação
O acesso a essa página exige autorização. Você pode tentar entrar ou alterar diretórios.
O acesso a essa página exige autorização. Você pode tentar alterar os diretórios.
Este artigo demonstra como criar todos os tipos de gráfico do Excel compatíveis com os Scripts do Office. Cada exemplo inclui dados e apresenta APIs específicas para esse tipo de gráfico. Use esses exemplos como pontos de partida para suas próprias soluções de criação de gráficos.
Observação
Execute esses exemplos diretamente no Editor de Código de Scripts do Office. Para abrir o Editor de códigos, acesse Automatizar> a criação denovo script>no Editor de códigos. Substitua o código padrão pelo código de exemplo que você deseja executar e selecione Executar.
Dica
Para obter os melhores resultados, execute cada exemplo em uma planilha vazia.
Gráficos de colunas
Os gráficos de colunas exibem dados como barras verticais, tornando-os ideais para comparar valores entre categorias.
Gráfico clusterizado de colunas
Este exemplo cria um gráfico de colunas clusterizado que compara as vendas trimestrais em diferentes produtos.
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Product", "Q1", "Q2", "Q3", "Q4"],
["Laptops", 45000, 52000, 48000, 61000],
["Tablets", 32000, 35000, 38000, 42000],
["Phones", 28000, 31000, 29000, 35000]
];
const dataRange = sheet.getRange("A1:E4");
dataRange.setValues(data);
// Create column clustered chart.
const chart = sheet.addChart(
ExcelScript.ChartType.columnClustered,
dataRange
);
chart.setPosition("A6");
chart.getTitle().setText("Quarterly Sales by Product");
// Customize the chart.
chart.getLegend().setPosition(ExcelScript.ChartLegendPosition.bottom);
chart.getAxes().getValueAxis().setDisplayUnit(ExcelScript.ChartAxisDisplayUnit.thousands);
}
Gráfico empilhado de colunas
Este exemplo cria um gráfico de colunas empilhadas que mostra a composição das vendas por região.
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Month", "North", "South", "East", "West"],
["Jan", 15000, 18000, 22000, 19000],
["Feb", 17000, 19000, 21000, 20000],
["Mar", 19000, 21000, 23000, 22000],
["Apr", 21000, 22000, 25000, 24000]
];
const dataRange = sheet.getRange("A1:E5");
dataRange.setValues(data);
// Create stacked column chart.
const chart = sheet.addChart(
ExcelScript.ChartType.columnStacked,
dataRange
);
chart.setPosition("A7");
chart.getTitle().setText("Regional Sales Contribution");
// Customize chart.
chart.getLegend().setPosition(ExcelScript.ChartLegendPosition.right);
chart.getAxes().getCategoryAxis().setReversePlotOrder(false);
}
Gráfico de colunas 100% empilhadas
Este exemplo cria um gráfico de colunas 100% empilhadas que mostra a distribuição percentual.
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Category", "Desktop", "Mobile", "Tablet"],
["Q1", 5500, 3200, 1300],
["Q2", 4800, 3800, 1400],
["Q3", 4200, 4100, 1700],
["Q4", 3900, 4500, 1600]
];
const dataRange = sheet.getRange("A1:D5");
dataRange.setValues(data);
// Create 100% stacked column chart.
const chart = sheet.addChart(
ExcelScript.ChartType.columnStacked100,
dataRange
);
chart.setPosition("A7");
chart.getTitle().setText("Device Usage Distribution");
}
Gráficos de barras
Os gráficos de barras exibem dados como barras horizontais. Elas são úteis quando os nomes de categorias são longos ou você tem muitas categorias.
Gráfico de barras agrupadas
Este exemplo cria um gráfico de barras clusterizado que compara as classificações de desempenho dos funcionários.
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Employee", "Technical", "Communication", "Leadership"],
["Chantha Mean", 9.2, 8.8, 9.5],
["Marcio Alvez", 8.5, 9.1, 8.2],
["Sobia Khanam", 9.8, 9.3, 9.6],
["Altynbek Joldubai", 8.9, 8.5, 8.8],
["Adriana Mota", 9.5, 9.7, 9.2]
];
const dataRange = sheet.getRange("A1:D6");
dataRange.setValues(data);
// Create bar clustered chart.
const chart = sheet.addChart(
ExcelScript.ChartType.barClustered,
dataRange
);
chart.setPosition("A8");
chart.getTitle().setText("Employee Performance Ratings");
// Customize.
chart.getLegend().setPosition(ExcelScript.ChartLegendPosition.bottom);
chart.getAxes().getValueAxis().setMinimum(0);
chart.getAxes().getValueAxis().setMaximum(10);
}
Gráfico de barras empilhadas
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Project Phase", "Planning", "Development", "Testing", "Deployment"],
["Project A", 2, 6, 3, 1],
["Project B", 3, 8, 4, 2],
["Project C", 1, 5, 2, 1]
];
const dataRange = sheet.getRange("A1:E4");
dataRange.setValues(data);
// Create bar stacked chart.
const chart = sheet.addChart(
ExcelScript.ChartType.barStacked,
dataRange
);
chart.setPosition("A6");
chart.getTitle().setText("Project Timeline (Weeks)");
chart.getLegend().setPosition(ExcelScript.ChartLegendPosition.bottom);
}
Gráfico de barras 100% empilhadas
Este exemplo cria um gráfico de barras 100% empilhadas que mostra a distribuição percentual entre as categorias.
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Quarter", "Product A", "Product B", "Product C", "Product D"],
["Q1", 45000, 32000, 28000, 15000],
["Q2", 52000, 35000, 31000, 18000],
["Q3", 48000, 38000, 35000, 22000],
["Q4", 56000, 42000, 38000, 24000]
];
const dataRange = sheet.getRange("A1:E5");
dataRange.setValues(data);
// Create 100% stacked bar chart.
const chart = sheet.addChart(
ExcelScript.ChartType.barStacked100,
dataRange
);
chart.setPosition("A7");
chart.getTitle().setText("Quarterly Sales Mix by Product (%)");
chart.getLegend().setPosition(ExcelScript.ChartLegendPosition.bottom);
}
Gráficos de linhas
Os gráficos de linhas mostram tendências ao longo do tempo. Eles são perfeitos para exibir dados contínuos.
Gráfico de linhas
Este exemplo cria um gráfico de linhas básico que mostra as tendências de temperatura.
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Month", "Avg Temp (°F)"],
["Jan", 42],
["Feb", 45],
["Mar", 52],
["Apr", 61],
["May", 70],
["Jun", 78],
["Jul", 84],
["Aug", 82],
["Sep", 75],
["Oct", 64],
["Nov", 53],
["Dec", 45]
];
const dataRange = sheet.getRange("A1:B13");
dataRange.setValues(data);
// Create line chart.
const chart = sheet.addChart(
ExcelScript.ChartType.line,
dataRange
);
chart.setPosition("D1");
chart.getTitle().setText("Average Monthly Temperature");
// Customize line chart.
chart.getAxes().getCategoryAxis().setTickLabelPosition(
ExcelScript.ChartAxisTickLabelPosition.low
);
chart.getAxes().getValueAxis().getMajorGridlines().getFormat().getLine().setColor("gray");
}
Linha com gráfico de marcadores
Este exemplo cria um gráfico de linhas com marcadores para enfatizar pontos de dados individuais.
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Week", "Website A", "Website B", "Website C"],
["Week 1", 1250, 980, 1100],
["Week 2", 1380, 1050, 1150],
["Week 3", 1520, 1180, 1320],
["Week 4", 1690, 1280, 1450],
["Week 5", 1850, 1420, 1580],
["Week 6", 2020, 1590, 1720]
];
const dataRange = sheet.getRange("A1:D7");
dataRange.setValues(data);
// Create line chart with markers.
const chart = sheet.addChart(
ExcelScript.ChartType.lineMarkers,
dataRange
);
chart.setPosition("A9");
chart.getTitle().setText("Weekly Visitor Growth");
// Customize markers.
const series = chart.getSeries();
series.forEach((s) => {
s.setMarkerSize(8);
s.setMarkerStyle(ExcelScript.ChartMarkerStyle.circle);
});
}
Gráfico empilhado de linhas
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Quarter", "Product A", "Product B", "Product C"],
["Q1 2024", 25000, 18000, 12000],
["Q2 2024", 28000, 20000, 14000],
["Q3 2024", 32000, 22000, 16000],
["Q4 2024", 35000, 25000, 18000]
];
const dataRange = sheet.getRange("A1:D5");
dataRange.setValues(data);
// Create stacked line chart.
const chart = sheet.addChart(
ExcelScript.ChartType.lineStacked,
dataRange
);
chart.setPosition("A7");
chart.getTitle().setText("Cumulative Product Revenue");
chart.getLegend().setPosition(ExcelScript.ChartLegendPosition.top);
}
Gráfico 100% empilhado
Este exemplo cria um gráfico de linhas 100% empilhadas mostrando a distribuição percentual ao longo do tempo.
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Month", "Email", "Social", "Direct"],
["Jan", 450, 320, 230],
["Feb", 480, 350, 270],
["Mar", 520, 380, 300],
["Apr", 560, 420, 320],
["May", 590, 450, 360],
["Jun", 630, 490, 380]
];
const dataRange = sheet.getRange("A1:D7");
dataRange.setValues(data);
// Create 100% stacked line chart.
const chart = sheet.addChart(
ExcelScript.ChartType.lineStacked100,
dataRange
);
chart.setPosition("A9");
chart.getTitle().setText("Traffic Source Distribution Over Time");
chart.getLegend().setPosition(ExcelScript.ChartLegendPosition.bottom);
}
Linha com marcadores gráfico empilhado
Este exemplo cria um gráfico de linhas empilhadas com marcadores.
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Week", "Team A", "Team B", "Team C"],
["Week 1", 12, 8, 10],
["Week 2", 15, 10, 12],
["Week 3", 18, 13, 15],
["Week 4", 22, 16, 18],
["Week 5", 25, 19, 21]
];
const dataRange = sheet.getRange("A1:D6");
dataRange.setValues(data);
// Create stacked line chart with markers.
const chart = sheet.addChart(
ExcelScript.ChartType.lineMarkersStacked,
dataRange
);
chart.setPosition("A8");
chart.getTitle().setText("Cumulative Team Performance");
chart.getLegend().setPosition(ExcelScript.ChartLegendPosition.right);
}
Linha com marcadores empilhados gráfico 100%
Este exemplo cria um gráfico de linhas 100% empilhadas com marcadores.
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Quarter", "Product Line A", "Product Line B", "Product Line C"],
["Q1", 35, 40, 25],
["Q2", 38, 37, 25],
["Q3", 40, 35, 25],
["Q4", 42, 33, 25]
];
const dataRange = sheet.getRange("A1:D5");
dataRange.setValues(data);
// Create 100% stacked line chart with markers.
const chart = sheet.addChart(
ExcelScript.ChartType.lineMarkersStacked100,
dataRange
);
chart.setPosition("A7");
chart.getTitle().setText("Product Line Market Share Trends");
chart.getLegend().setPosition(ExcelScript.ChartLegendPosition.bottom);
}
Gráficos de pizza
Gráficos de pizza mostram relações proporcionais em um conjunto de dados. Cada valor aparece como uma fatia do todo.
Gráfico de pizza
Este exemplo cria um gráfico de pizza que mostra a distribuição da participação no mercado.
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data with multiple slices.
const data = [
["Company", "Market Share"],
["Alpha Corp", 28.5],
["Beta Inc", 22.3],
["Gamma LLC", 18.7],
["Delta Co", 15.2],
["Others", 15.3]
];
const dataRange = sheet.getRange("A1:B6");
dataRange.setValues(data);
// Create pie chart.
const chart = sheet.addChart(
ExcelScript.ChartType.pie,
dataRange
);
chart.setPosition("D1");
chart.getTitle().setText("Market Share Distribution");
// Customize pie chart.
chart.getLegend().setPosition(ExcelScript.ChartLegendPosition.right);
// Add data labels showing percentages.
const series = chart.getSeries()[0];
series.setHasDataLabels(true);
series.getDataLabels().setShowPercentage(true);
series.getDataLabels().setShowSeriesName(false);
series.getDataLabels().setShowCategoryName(false);
series.getDataLabels().setShowValue(false);
}
Gráfico de pizza destacado
Este exemplo cria um gráfico de pizza destacado com fatias separadas para dar ênfase.
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Expense Category", "Amount"],
["Housing", 1800],
["Transportation", 650],
["Food", 550],
["Utilities", 200],
["Entertainment", 300],
["Savings", 500]
];
const dataRange = sheet.getRange("A1:B7");
dataRange.setValues(data);
// Create exploded pie chart.
const chart = sheet.addChart(
ExcelScript.ChartType.pieExploded,
dataRange
);
chart.setPosition("D1");
chart.getTitle().setText("Monthly Budget Breakdown");
// Customize.
const series = chart.getSeries()[0];
series.setHasDataLabels(true);
series.getDataLabels().setShowCategoryName(true);
series.getDataLabels().setShowValue(true);
series.getDataLabels().setPosition(ExcelScript.ChartDataLabelPosition.bestFit);
}
Gráficos de rosca
Os gráficos de rosca são semelhantes aos gráficos de pizza, mas podem exibir várias séries de dados e ter uma abertura no centro.
Gráfico de rosca
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Category", "2024"],
["Hardware", 45000],
["Software", 32000],
["Services", 28000],
["Training", 15000],
["Support", 20000]
];
const dataRange = sheet.getRange("A1:B6");
dataRange.setValues(data);
// Create doughnut chart.
const chart = sheet.addChart(
ExcelScript.ChartType.doughnut,
dataRange
);
chart.setPosition("D1");
chart.getTitle().setText("Revenue by Category");
// Customize doughnut chart.
const series = chart.getSeries()[0];
series.setHasDataLabels(true);
series.getDataLabels().setShowPercentage(true);
series.getDataLabels().setShowLeaderLines(true);
chart.getLegend().setPosition(ExcelScript.ChartLegendPosition.bottom);
}
Gráfico de rosca destacado
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Region", "Sales %"],
["North America", 35.2],
["Europe", 28.7],
["Asia Pacific", 22.3],
["Latin America", 8.5],
["Others", 5.3]
];
const dataRange = sheet.getRange("A1:B6");
dataRange.setValues(data);
// Create exploded doughnut chart.
const chart = sheet.addChart(
ExcelScript.ChartType.doughnutExploded,
dataRange
);
chart.setPosition("D1");
chart.getTitle().setText("Regional Sales Distribution");
chart.getLegend().setPosition(ExcelScript.ChartLegendPosition.right);
}
Gráficos de áreas
Os gráficos de áreas enfatizam a magnitude da mudança ao longo do tempo e mostram o total acumulado.
Gráfico de área
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Month", "Revenue"],
["Jan", 45000],
["Feb", 52000],
["Mar", 48000],
["Apr", 61000],
["May", 58000],
["Jun", 67000]
];
const dataRange = sheet.getRange("A1:B7");
dataRange.setValues(data);
// Create area chart.
const chart = sheet.addChart(
ExcelScript.ChartType.area,
dataRange
);
chart.setPosition("D1");
chart.getTitle().setText("Monthly Revenue Trend");
// Customize area chart.
chart.getAxes().getValueAxis().setDisplayUnit(
ExcelScript.ChartAxisDisplayUnit.thousands
);
}
Gráfico de áreas empilhadas
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["", "Solar", "Wind", "Hydro", "Geothermal"],
["2020", 150, 120, 200, 30],
["2021", 180, 145, 205, 35],
["2022", 220, 175, 210, 40],
["2023", 270, 210, 215, 48],
["2024", 330, 250, 220, 55]
];
const dataRange = sheet.getRange("A1:E6");
dataRange.setValues(data);
// Create stacked area chart.
const chart = sheet.addChart(
ExcelScript.ChartType.areaStacked,
dataRange
);
chart.setPosition("A8");
chart.getTitle().setText("Renewable Energy Production (TWh)");
chart.getLegend().setPosition(ExcelScript.ChartLegendPosition.top);
}
Gráfico de áreas 100% empilhadas
Este exemplo cria um gráfico de áreas 100% empilhadas mostrando a distribuição percentual ao longo do tempo.
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["", "Solar", "Wind", "Hydro", "Geothermal"],
["2020", 150, 120, 200, 30],
["2021", 180, 145, 205, 35],
["2022", 220, 175, 210, 40],
["2023", 270, 210, 215, 48],
["2024", 330, 250, 220, 55]
];
const dataRange = sheet.getRange("A1:E6");
dataRange.setValues(data);
// Create 100% stacked area chart.
const chart = sheet.addChart(
ExcelScript.ChartType.areaStacked100,
dataRange
);
chart.setPosition("A8");
chart.getTitle().setText("Renewable Energy Mix (% Distribution)");
// Label the series with energy source names.
const seriesCollection = chart.getSeries();
seriesCollection[0].setName("Solar");
seriesCollection[1].setName("Wind");
seriesCollection[2].setName("Hydro");
seriesCollection[3].setName("Geothermal");
chart.getLegend().setPosition(ExcelScript.ChartLegendPosition.top);
}
Gráficos de dispersão (XY)
Os gráficos de dispersão mostram relações entre duas variáveis numéricas. Use-os para análise de correlação.
Gráfico de dispersão
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Study Hours", "Test Score"],
[2, 65],
[3, 68],
[4, 72],
[5, 75],
[5.5, 78],
[6, 82],
[7, 85],
[7.5, 88],
[8, 90],
[9, 92],
[10, 95]
];
const dataRange = sheet.getRange("A1:B12");
dataRange.setValues(data);
// Create scatter chart.
const chart = sheet.addChart(
ExcelScript.ChartType.xyscatter,
dataRange
);
chart.setPosition("D1");
chart.getTitle().setText("Study Hours vs Test Scores");
// Customize scatter chart.
chart.getAxes().getCategoryAxis().setDisplayUnit(ExcelScript.ChartAxisDisplayUnit.none);
chart.getAxes().getValueAxis().setMinimum(0);
chart.getAxes().getValueAxis().setMaximum(100);
// Remove legend as there's only one series.
chart.getLegend().setVisible(false);
}
Gráfico de dispersão com linhas
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Temperature (°C)", "Sales ($)"],
[15, 2500],
[18, 2800],
[22, 3200],
[25, 3800],
[28, 4500],
[32, 5200],
[35, 5800],
[38, 6100]
];
const dataRange = sheet.getRange("A1:B9");
dataRange.setValues(data);
// Create scatter chart with lines.
const chart = sheet.addChart(
ExcelScript.ChartType.xyscatterLines,
dataRange
);
chart.setPosition("D1");
chart.getTitle().setText("Ice Cream Sales vs Temperature");
chart.getLegend().setVisible(false);
}
Gráfico de dispersão com linhas suaves
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["X", "Series 1", "Series 2"],
[1, 10, 15],
[2, 15, 18],
[3, 25, 22],
[4, 40, 28],
[5, 60, 35],
[6, 85, 43],
[7, 115, 52]
];
const dataRange = sheet.getRange("A1:C8");
dataRange.setValues(data);
// Create scatter chart with smooth lines.
const chart = sheet.addChart(
ExcelScript.ChartType.xyscatterSmooth,
dataRange
);
chart.setPosition("D1");
chart.getTitle().setText("Growth Comparison");
chart.getLegend().setPosition(ExcelScript.ChartLegendPosition.bottom);
}
Gráfico de dispersão com linhas (sem marcadores)
Este exemplo cria um gráfico de dispersão com linhas de conexão, mas sem marcadores de ponto de dados.
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Time (hours)", "Distance (miles)"],
[0, 0],
[1, 55],
[2, 105],
[3, 160],
[4, 210],
[5, 265],
[6, 315]
];
const dataRange = sheet.getRange("A1:B8");
dataRange.setValues(data);
// Create scatter chart with lines but no markers.
const chart = sheet.addChart(
ExcelScript.ChartType.xyscatterLinesNoMarkers,
dataRange
);
chart.setPosition("D1");
chart.getTitle().setText("Travel Distance Over Time");
chart.getLegend().setVisible(false);
}
Gráfico de dispersão com linhas suaves (sem marcadores)
Este exemplo cria um gráfico de dispersão com linhas de conexão suaves, mas sem marcadores de ponto de dados.
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Input", "Output"],
[1, 5],
[2, 12],
[3, 22],
[4, 35],
[5, 51],
[6, 70],
[7, 92]
];
const dataRange = sheet.getRange("A1:B8");
dataRange.setValues(data);
// Create scatter chart with smooth lines but no markers.
const chart = sheet.addChart(
ExcelScript.ChartType.xyscatterSmoothNoMarkers,
dataRange
);
chart.setPosition("D1");
chart.getTitle().setText("Response Curve Analysis");
chart.getLegend().setVisible(false);
}
Gráficos de bolhas
Os gráficos de bolhas exibem três dimensões de dados: posição X e Y mais o tamanho da bolha.
Gráfico de bolhas
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data for bubble chart.
// Each product is a separate data series with X, Y, and Size values.
const data = [
["Product", "Price ($)", "Quality Score", "Market Share"],
["Laptops", 150, 85, 25],
["Tablets", 200, 90, 40],
["Phones", 100, 75, 15],
["Monitors", 250, 92, 35],
["Keyboards", 175, 88, 30],
["Mice", 120, 80, 20]
];
const dataRange = sheet.getRange("A1:D7");
dataRange.setValues(data);
// Create bubble chart - manually add each series.
const chart = sheet.addChart(
ExcelScript.ChartType.bubble,
sheet.getRange("B1:D1") // Start with just headers to create empty chart.
);
chart.setPosition("A9");
chart.getTitle().setText("Product Analysis: Price vs Quality (Market Share)");
// Remove any default series that were created.
while (chart.getSeries().length > 0) {
chart.getSeries()[0].delete();
}
// Add each product as its own series.
for (let i = 2; i <= 7; i++) {
const productName = sheet.getRange(`A${ i } `).getValue() as string;
const newSeries = chart.addChartSeries();
newSeries.setName(productName);
newSeries.setXAxisValues(sheet.getRange(`B${ i }:B${ i } `));
newSeries.setValues(sheet.getRange(`C${ i }:C${ i } `));
newSeries.setBubbleSizes(sheet.getRange(`D${ i }:D${ i } `));
}
chart.getLegend().setPosition(ExcelScript.ChartLegendPosition.right);
}
Gráfico de bolhas 3D
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data for 3D bubble chart.
// Each city is a separate data series with X, Y, and Size values.
const data = [
["City", "Population (millions)", "GDP per Capita ($k)", "Area (km²)"],
["Tokyo", 8.5, 65, 300],
["Berlin", 3.2, 58, 150],
["Sydney", 5.8, 72, 250],
["Toronto", 2.1, 52, 100],
["Singapore", 4.5, 68, 180]
];
const dataRange = sheet.getRange("A1:D6");
dataRange.setValues(data);
// Create 3D bubble chart - manually add each series.
const chart = sheet.addChart(
ExcelScript.ChartType.bubble3DEffect,
sheet.getRange("B1:D1") // Start with just headers to create empty chart.
);
chart.setPosition("A8");
chart.getTitle().setText("City Comparison: Population vs GDP per Capita (Area)");
// Remove any default series that were created.
while (chart.getSeries().length > 0) {
chart.getSeries()[0].delete();
}
// Add each city as its own series.
for (let i = 2; i <= 6; i++) {
const cityName = sheet.getRange(`A${ i } `).getValue() as string;
const newSeries = chart.addChartSeries();
newSeries.setName(cityName);
newSeries.setXAxisValues(sheet.getRange(`B${ i }:B${ i } `));
newSeries.setValues(sheet.getRange(`C${ i }:C${ i } `));
newSeries.setBubbleSizes(sheet.getRange(`D${ i }:D${ i } `));
}
chart.getLegend().setPosition(ExcelScript.ChartLegendPosition.bottom);
}
Gráficos de ações
Os gráficos de ações exibem dados financeiros com valores altos, baixos e próximos. Eles também podem incluir valores de abertura e volume.
Gráfico HLC de estoque
Este exemplo cria um gráfico de ações Alta-Baixa-Fechamento.
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data (Date, High, Low, Close).
const data = [
["Date", "High", "Low", "Close"],
["1/1/2024", 152.50, 148.20, 151.00],
["1/2/2024", 153.80, 150.50, 152.30],
["1/3/2024", 154.20, 151.80, 153.50],
["1/4/2024", 155.00, 152.30, 153.80],
["1/5/2024", 156.50, 153.50, 155.20]
];
const dataRange = sheet.getRange("A1:D6");
dataRange.setValues(data);
// Create HLC stock chart.
const chart = sheet.addChart(
ExcelScript.ChartType.stockHLC,
dataRange
);
chart.setPosition("A8");
chart.getTitle().setText("Stock Price Movement (HLC)");
// Customize stock chart.
chart.getAxes().getValueAxis().setMinimum(145);
chart.getAxes().getValueAxis().setMaximum(160);
}
Gráfico OHLC de ações
Este exemplo cria um gráfico de ações Abertura-Alta-Baixa-Fechamento.
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data (Date, Open, High, Low, Close).
const data = [
["Date", "Open", "High", "Low", "Close"],
["1/1/2024", 150.00, 152.50, 148.20, 151.00],
["1/2/2024", 151.00, 153.80, 150.50, 152.30],
["1/3/2024", 152.30, 154.20, 151.80, 153.50],
["1/4/2024", 153.50, 155.00, 152.30, 153.80],
["1/5/2024", 153.80, 156.50, 153.50, 155.20]
];
const dataRange = sheet.getRange("A1:E6");
dataRange.setValues(data);
// Create OHLC stock chart.
const chart = sheet.addChart(
ExcelScript.ChartType.stockOHLC,
dataRange
);
chart.setPosition("A8");
chart.getTitle().setText("Stock Price Movement (OHLC)");
chart.getAxes().getValueAxis().setMinimum(145);
chart.getAxes().getValueAxis().setMaximum(160);
}
Gráfico VHLC de ações
Este exemplo cria um gráfico de ações Volume-High-Low-Close.
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data (Date, Volume, High, Low, Close).
const data = [
["Date", "Volume", "High", "Low", "Close"],
["1/1/2024", 2500000, 152.50, 148.20, 151.00],
["1/2/2024", 3200000, 153.80, 150.50, 152.30],
["1/3/2024", 2800000, 154.20, 151.80, 153.50],
["1/4/2024", 3500000, 155.00, 152.30, 153.80],
["1/5/2024", 4100000, 156.50, 153.50, 155.20]
];
const dataRange = sheet.getRange("A1:E6");
dataRange.setValues(data);
// Create VHLC stock chart.
const chart = sheet.addChart(
ExcelScript.ChartType.stockVHLC,
dataRange
);
chart.setPosition("A8");
chart.getTitle().setText("Stock Price with Volume (VHLC)");
// Customize to improve visibility of stock lines against volume bars.
chart.getAxes().getValueAxis().setMinimum(145);
chart.getAxes().getValueAxis().setMaximum(160);
// Make the volume bars more transparent or lighter colored.
const volumeSeries = chart.getSeries()[0];
volumeSeries.getFormat().getFill().setSolidColor("#B0C4DE"); // Light steel blue.
}
Gráfico VOHLC de ações
Este exemplo cria um gráfico de ações de Volume-Abertura-Alta-Baixa-Fechamento.
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data (Date, Volume, Open, High, Low, Close).
const data = [
["Date", "Volume", "Open", "High", "Low", "Close"],
["1/1/2024", 2500000, 150.00, 152.50, 148.20, 151.00],
["1/2/2024", 3200000, 151.00, 153.80, 150.50, 152.30],
["1/3/2024", 2800000, 152.30, 154.20, 151.80, 153.50],
["1/4/2024", 3500000, 153.50, 155.00, 152.30, 153.80],
["1/5/2024", 4100000, 153.80, 156.50, 153.50, 155.20]
];
const dataRange = sheet.getRange("A1:F6");
dataRange.setValues(data);
// Create VOHLC stock chart.
const chart = sheet.addChart(
ExcelScript.ChartType.stockVOHLC,
dataRange
);
chart.setPosition("A8");
chart.getTitle().setText("Complete Stock Analysis (VOHLC)");
// Customize to improve visibility of stock lines against volume bars.
chart.getAxes().getValueAxis().setMinimum(145);
chart.getAxes().getValueAxis().setMaximum(160);
// Make the volume bars more transparent or lighter colored.
const volumeSeries = chart.getSeries()[0];
volumeSeries.getFormat().getFill().setSolidColor("#B0C4DE"); // Light steel blue.
}
Gráficos de radar
Os gráficos de radar exibem dados multivariados em eixos que começam no mesmo ponto. Eles são úteis para comparar várias variáveis.
Gráfico de radar
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Attribute", "Product A", "Product B"],
["Speed", 8, 6],
["Reliability", 9, 8],
["Cost", 6, 9],
["Features", 7, 8],
["Support", 8, 7],
["Ease of Use", 9, 9]
];
const dataRange = sheet.getRange("A1:C7");
dataRange.setValues(data);
// Create radar chart.
const chart = sheet.addChart(
ExcelScript.ChartType.radar,
dataRange
);
chart.setPosition("D1");
chart.getTitle().setText("Product Comparison Radar");
chart.getLegend().setPosition(ExcelScript.ChartLegendPosition.bottom);
}
Radar com gráfico de marcadores
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Skill", "Danaite Alemseged", "Fazekas Peter", "Jeffry Goh"],
["JavaScript", 9, 7, 8],
["Python", 7, 9, 6],
["SQL", 8, 8, 9],
["Cloud", 8, 6, 7],
["DevOps", 6, 8, 9]
];
const dataRange = sheet.getRange("A1:D6");
dataRange.setValues(data);
// Create radar chart with markers.
const chart = sheet.addChart(
ExcelScript.ChartType.radarMarkers,
dataRange
);
chart.setPosition("A8");
chart.getTitle().setText("Developer Skill Assessment");
chart.getLegend().setPosition(ExcelScript.ChartLegendPosition.right);
}
Gráfico de radar preenchido
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data - Target first, then Current so Current is drawn on top.
const data = [
["Category", "Target", "Current"],
["Customer Satisfaction", 9.0, 7.5],
["Product Quality", 9.5, 8.2],
["Delivery Speed", 9.0, 6.8],
["Price Competitiveness", 8.5, 7.0],
["Innovation", 9.5, 8.5],
["Market Presence", 9.0, 7.2]
];
const dataRange = sheet.getRange("A1:C7");
dataRange.setValues(data);
// Create filled radar chart.
const chart = sheet.addChart(
ExcelScript.ChartType.radarFilled,
dataRange
);
chart.setPosition("D1");
chart.getTitle().setText("Performance vs Target Metrics");
chart.getLegend().setPosition(ExcelScript.ChartLegendPosition.bottom);
}
Gráficos de mapa de árvore
Os gráficos de mapa de árvore exibem dados hierárquicos como retângulos aninhados, com tamanho representando valores.
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Category", "Subcategory", "Value"],
["Electronics", "Phones", 45000],
["Electronics", "Laptops", 38000],
["Electronics", "Tablets", 22000],
["Furniture", "Desks", 18000],
["Furniture", "Chairs", 25000],
["Furniture", "Storage", 12000],
["Clothing", "Shirts", 15000],
["Clothing", "Pants", 18000],
["Clothing", "Accessories", 8000]
];
const dataRange = sheet.getRange("A1:C10");
dataRange.setValues(data);
// Create treemap chart.
const chart = sheet.addChart(
ExcelScript.ChartType.treemap,
dataRange
);
chart.setPosition("D1");
chart.getTitle().setText("Sales by Category (Treemap)");
// Treemap-specific customization.
chart.getLegend().setVisible(false);
}
Gráficos de explosão solar
Os gráficos de explosão solar exibem dados hierárquicos em círculos concêntricos, com cada nível representado por um anel.
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Level 1", "Level 2", "Level 3", "Value"],
["Sales", "North America", "USA", 125000],
["Sales", "North America", "Canada", 35000],
["Sales", "Europe", "UK", 45000],
["Sales", "Europe", "Germany", 52000],
["Sales", "Europe", "France", 38000],
["Marketing", "Digital", "Social Media", 28000],
["Marketing", "Digital", "Email", 15000],
["Marketing", "Traditional", "Print", 12000],
["Marketing", "Traditional", "TV", 35000]
];
const dataRange = sheet.getRange("A1:D10");
dataRange.setValues(data);
// Create sunburst chart.
const chart = sheet.addChart(
ExcelScript.ChartType.sunburst,
dataRange
);
chart.setPosition("E1");
chart.getTitle().setText("Organizational Revenue Breakdown");
chart.getLegend().setVisible(false);
}
Gráficos em cascata
Os gráficos de cascata mostram como um valor inicial é afetado por valores positivos e negativos, exibindo o efeito cumulativo.
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Category", "Amount"],
["Starting Balance", 50000],
["Revenue", 125000],
["Cost of Goods", -45000],
["Operating Expenses", -32000],
["Marketing", -15000],
["Taxes", -18000],
["Ending Balance", 65000]
];
const dataRange = sheet.getRange("A1:B8");
dataRange.setValues(data);
// Create waterfall chart.
const chart = sheet.addChart(
ExcelScript.ChartType.waterfall,
dataRange
);
chart.setPosition("D1");
chart.getTitle().setText("Profit & Loss Analysis");
// Waterfall charts automatically handle the flow visualization.
chart.getLegend().setVisible(false);
}
Gráficos de funil
Os gráficos de funil mostram uma redução progressiva de dados ao longo de estágios. Use-os para análise de vendas e conversão.
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Stage", "Count"],
["Website Visitors", 10000],
["Product Page Views", 4500],
["Add to Cart", 1200],
["Started Checkout", 800],
["Completed Purchase", 450]
];
const dataRange = sheet.getRange("A1:B6");
dataRange.setValues(data);
// Create funnel chart.
const chart = sheet.addChart(
ExcelScript.ChartType.funnel,
dataRange
);
chart.setPosition("D1");
chart.getTitle().setText("Sales Funnel Conversion");
}
Gráficos de caixas estreitas
Gráficos de caixa estreita mostram a distribuição dos dados por quartis. Eles destacam a mediana e os valores discrepantes.
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data (multiple observations per category).
const data = [
["Region", "Response Time (ms)"],
["North", 245],
["North", 268],
["North", 232],
["North", 289],
["North", 251],
["South", 312],
["South", 298],
["South", 334],
["South", 305],
["South", 321],
["East", 198],
["East", 215],
["East", 187],
["East", 223],
["East", 206],
["West", 267],
["West", 281],
["West", 254],
["West", 273],
["West", 269]
];
const dataRange = sheet.getRange("A1:B21");
dataRange.setValues(data);
// Create box and whisker chart.
const chart = sheet.addChart(
ExcelScript.ChartType.boxwhisker,
dataRange
);
chart.setPosition("D1");
chart.getTitle().setText("Response Time Distribution by Region");
chart.getLegend().setVisible(false);
}
Gráficos de histograma
Os gráficos de histograma exibem a distribuição de dados numéricos agrupando os valores em compartimentos.
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data (customer ages).
const data = [
["Customer", "Age"],
["Customer 1", 23],
["Customer 2", 45],
["Customer 3", 31],
["Customer 4", 52],
["Customer 5", 28],
["Customer 6", 67],
["Customer 7", 38],
["Customer 8", 41],
["Customer 9", 29],
["Customer 10", 55],
["Customer 11", 33],
["Customer 12", 48],
["Customer 13", 26],
["Customer 14", 62],
["Customer 15", 35],
["Customer 16", 44],
["Customer 17", 58],
["Customer 18", 37],
["Customer 19", 49],
["Customer 20", 71],
["Customer 21", 24],
["Customer 22", 39],
["Customer 23", 56],
["Customer 24", 42],
["Customer 25", 64]
];
const dataRange = sheet.getRange("A1:B26");
dataRange.setValues(data);
// Create histogram chart.
const chart = sheet.addChart(
ExcelScript.ChartType.histogram,
dataRange
);
chart.setPosition("D1");
chart.getTitle().setText("Customer Age Distribution");
chart.getLegend().setVisible(false);
}
Gráficos de pareto
Os gráficos de pareto combinam gráficos de colunas e de linhas para mostrar os valores individuais e os totais acumulados. Eles seguem o princípio 80/20.
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Defect Type", "Frequency"],
["Packaging", 45],
["Assembly", 32],
["Quality Control", 28],
["Material", 18],
["Design", 12],
["Shipping", 8],
["Documentation", 5],
["Other", 3]
];
const dataRange = sheet.getRange("A1:B9");
dataRange.setValues(data);
// Create pareto chart.
const chart = sheet.addChart(
ExcelScript.ChartType.pareto,
dataRange
);
chart.setPosition("D1");
chart.getTitle().setText("Defect Analysis (Pareto)");
chart.getLegend().setPosition(ExcelScript.ChartLegendPosition.bottom);
}
Gráficos de superfície
Os gráficos de superfície exibem tendências em valores em duas dimensões em uma curva contínua. Eles são úteis para encontrar combinações ideais.
Gráfico de superfície
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data (temperature at different coordinates).
const data = [
["", "0", "5", "10", "15", "20"],
["0", 20, 22, 25, 28, 30],
["5", 22, 24, 27, 30, 32],
["10", 25, 27, 30, 33, 35],
["15", 28, 30, 33, 36, 38],
["20", 30, 32, 35, 38, 40]
];
const dataRange = sheet.getRange("A1:F6");
dataRange.setValues(data);
// Create surface chart.
const chart = sheet.addChart(
ExcelScript.ChartType.surface,
dataRange
);
chart.setPosition("A8");
chart.getTitle().setText("Temperature Distribution (3D Surface)");
chart.getLegend().setPosition(ExcelScript.ChartLegendPosition.right);
}
Gráfico de estrutura de arame de superfície
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["", "A", "B", "C", "D", "E"],
["1", 10, 15, 20, 15, 10],
["2", 15, 25, 35, 25, 15],
["3", 20, 35, 50, 35, 20],
["4", 15, 25, 35, 25, 15],
["5", 10, 15, 20, 15, 10]
];
const dataRange = sheet.getRange("A1:F6");
dataRange.setValues(data);
// Create surface wireframe chart.
const chart = sheet.addChart(
ExcelScript.ChartType.surfaceWireframe,
dataRange
);
chart.setPosition("A8");
chart.getTitle().setText("Data Surface (Wireframe)");
chart.getLegend().setVisible(false);
}
Gráfico de contorno (exibição superior da superfície)
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["", "0°", "45°", "90°", "135°", "180°"],
["0m", 100, 95, 85, 92, 98],
["10m", 95, 88, 75, 85, 93],
["20m", 85, 78, 62, 75, 83],
["30m", 92, 85, 75, 82, 90],
["40m", 98, 93, 83, 90, 96]
];
const dataRange = sheet.getRange("A1:F6");
dataRange.setValues(data);
// Create contour (top view) chart.
const chart = sheet.addChart(
ExcelScript.ChartType.surfaceTopView,
dataRange
);
chart.setPosition("A8");
chart.getTitle().setText("Signal Strength Map (Contour)");
chart.getLegend().setPosition(ExcelScript.ChartLegendPosition.right);
}
Gráfico de contorno Wireframe (Surface Top View Wireframe)
Este exemplo cria uma versão delineada de um gráfico de contorno.
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["", "0°", "45°", "90°", "135°", "180°"],
["0m", 100, 95, 85, 92, 98],
["10m", 95, 88, 75, 85, 93],
["20m", 85, 78, 62, 75, 83],
["30m", 92, 85, 75, 82, 90],
["40m", 98, 93, 83, 90, 96]
];
const dataRange = sheet.getRange("A1:F6");
dataRange.setValues(data);
// Create contour wireframe chart.
const chart = sheet.addChart(
ExcelScript.ChartType.surfaceTopViewWireframe,
dataRange
);
chart.setPosition("A8");
chart.getTitle().setText("Signal Strength Map (Contour Wireframe)");
chart.getLegend().setPosition(ExcelScript.ChartLegendPosition.right);
}
Gráficos de mapa de regiões
Os gráficos de mapa de regiões, também chamados de gráficos de mapa preenchidos, exibem valores entre regiões geográficas.
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data (state names and values).
const data = [
["State", "Sales"],
["California", 450000],
["Texas", 380000],
["Florida", 320000],
["New York", 410000],
["Illinois", 280000],
["Pennsylvania", 240000],
["Ohio", 220000],
["Georgia", 195000],
["North Carolina", 185000],
["Michigan", 175000]
];
const dataRange = sheet.getRange("A1:B11");
dataRange.setValues(data);
// Create region map chart.
const chart = sheet.addChart(
ExcelScript.ChartType.regionMap,
dataRange
);
chart.setPosition("D1");
chart.getTitle().setText("Sales by State");
chart.getLegend().setPosition(ExcelScript.ChartLegendPosition.right);
}
Gráficos de combinação (combinação de barra/pizza)
Barra do gráfico de pizza
A barra de gráficos de pizza divide fatias menores de um gráfico de pizza em uma barra separada para melhor visibilidade.
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Category", "Amount"],
["Category A", 45],
["Category B", 30],
["Category C", 15],
["Category D", 4],
["Category E", 3],
["Category F", 2],
["Category G", 1]
];
const dataRange = sheet.getRange("A1:B8");
dataRange.setValues(data);
// Create bar of pie chart.
const chart = sheet.addChart(
ExcelScript.ChartType.barOfPie,
dataRange
);
chart.setPosition("D1");
chart.getTitle().setText("Category Distribution (Bar of Pie)");
chart.getLegend().setPosition(ExcelScript.ChartLegendPosition.bottom);
}
Pizza do gráfico de pizza
Os gráficos de pizza exibem um gráfico de pizza secundário que mostra detalhes de fatias menores.
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Segment", "Value"],
["Enterprise", 425000],
["Small Business", 285000],
["Consumer", 190000],
["Education", 65000],
["Government", 55000],
["Non-Profit", 30000]
];
const dataRange = sheet.getRange("A1:B7");
dataRange.setValues(data);
// Create pie of pie chart.
const chart = sheet.addChart(
ExcelScript.ChartType.pieOfPie,
dataRange
);
chart.setPosition("D1");
chart.getTitle().setText("Market Segment Analysis (Pie of Pie)");
chart.getLegend().setPosition(ExcelScript.ChartLegendPosition.right);
}
Variações do gráfico 3D
Esses tipos de gráfico exibem dados com efeitos visuais tridimensionais usando as formas de cone, cilindro e pirâmide.
Gráficos de colunas de cone
Gráfico de colunas de cone
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Quarter", "Target", "Achieved"],
["Q1", 100000, 95000],
["Q2", 120000, 125000],
["Q3", 130000, 128000],
["Q4", 150000, 158000]
];
const dataRange = sheet.getRange("A1:C5");
dataRange.setValues(data);
// Create cone column chart.
const chart = sheet.addChart(
ExcelScript.ChartType.coneCol,
dataRange
);
chart.setPosition("D1");
chart.getTitle().setText("Quarterly Performance (3D Cone)");
chart.getLegend().setPosition(ExcelScript.ChartLegendPosition.bottom);
}
Gráfico de colunas de cone clusterizado
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Quarter", "Target", "Achieved"],
["Q1", 100000, 95000],
["Q2", 120000, 125000],
["Q3", 130000, 128000],
["Q4", 150000, 158000]
];
const dataRange = sheet.getRange("A1:C5");
dataRange.setValues(data);
// Create clustered cone column chart.
const chart = sheet.addChart(
ExcelScript.ChartType.coneColClustered,
dataRange
);
chart.setPosition("D1");
chart.getTitle().setText("Quarterly Performance (Clustered 3D Cone)");
chart.getLegend().setPosition(ExcelScript.ChartLegendPosition.bottom);
}
Gráfico de colunas de cone empilhado
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Quarter", "Target", "Achieved"],
["Q1", 100000, 95000],
["Q2", 120000, 125000],
["Q3", 130000, 128000],
["Q4", 150000, 158000]
];
const dataRange = sheet.getRange("A1:C5");
dataRange.setValues(data);
// Create stacked cone column chart.
const chart = sheet.addChart(
ExcelScript.ChartType.coneColStacked,
dataRange
);
chart.setPosition("D1");
chart.getTitle().setText("Quarterly Performance (Stacked 3D Cone)");
chart.getLegend().setPosition(ExcelScript.ChartLegendPosition.bottom);
}
Gráfico de colunas de cone 100% empilhado
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Quarter", "Target", "Achieved"],
["Q1", 100000, 95000],
["Q2", 120000, 125000],
["Q3", 130000, 128000],
["Q4", 150000, 158000]
];
const dataRange = sheet.getRange("A1:C5");
dataRange.setValues(data);
// Create 100% stacked cone column chart.
const chart = sheet.addChart(
ExcelScript.ChartType.coneColStacked100,
dataRange
);
chart.setPosition("D1");
chart.getTitle().setText("Quarterly Performance (100% Stacked 3D Cone)");
chart.getLegend().setPosition(ExcelScript.ChartLegendPosition.bottom);
}
Gráficos de colunas de cilindro
Gráfico de colunas de cilindro
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Product", "Units Sold"],
["Laptops", 850],
["Tablets", 720],
["Phones", 640],
["Monitors", 580]
];
const dataRange = sheet.getRange("A1:B5");
dataRange.setValues(data);
// Create cylinder column chart.
const chart = sheet.addChart(
ExcelScript.ChartType.cylinderCol,
dataRange
);
chart.setPosition("D1");
chart.getTitle().setText("Product Sales (3D Cylinder)");
chart.getLegend().setVisible(false);
}
Gráfico de colunas de cilindro clusterizado
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Product", "2023", "2024"],
["Laptops", 850, 920],
["Tablets", 720, 780],
["Phones", 640, 710],
["Monitors", 580, 650]
];
const dataRange = sheet.getRange("A1:C5");
dataRange.setValues(data);
// Create clustered cylinder column chart.
const chart = sheet.addChart(
ExcelScript.ChartType.cylinderColClustered,
dataRange
);
chart.setPosition("D1");
chart.getTitle().setText("Product Sales by Year (Clustered 3D Cylinder)");
chart.getLegend().setPosition(ExcelScript.ChartLegendPosition.bottom);
}
Gráfico de colunas de cilindro empilhado
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Product", "2023", "2024"],
["Laptops", 850, 920],
["Tablets", 720, 780],
["Phones", 640, 710],
["Monitors", 580, 650]
];
const dataRange = sheet.getRange("A1:C5");
dataRange.setValues(data);
// Create stacked cylinder column chart.
const chart = sheet.addChart(
ExcelScript.ChartType.cylinderColStacked,
dataRange
);
chart.setPosition("D1");
chart.getTitle().setText("Product Sales by Year (Stacked 3D Cylinder)");
chart.getLegend().setPosition(ExcelScript.ChartLegendPosition.bottom);
}
Gráfico de colunas de cilindro 100% empilhado
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Product", "2023", "2024"],
["Laptops", 850, 920],
["Tablets", 720, 780],
["Phones", 640, 710],
["Monitors", 580, 650]
];
const dataRange = sheet.getRange("A1:C5");
dataRange.setValues(data);
// Create 100% stacked cylinder column chart.
const chart = sheet.addChart(
ExcelScript.ChartType.cylinderColStacked100,
dataRange
);
chart.setPosition("D1");
chart.getTitle().setText("Product Sales by Year (100% Stacked 3D Cylinder)");
chart.getLegend().setPosition(ExcelScript.ChartLegendPosition.bottom);
}
Gráficos de colunas em pirâmide
Gráfico de colunas em pirâmide
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Level", "Headcount"],
["Executive", 5],
["Senior Management", 25],
["Middle Management", 120],
["Staff", 450]
];
const dataRange = sheet.getRange("A1:B5");
dataRange.setValues(data);
// Create pyramid column chart.
const chart = sheet.addChart(
ExcelScript.ChartType.pyramidCol,
dataRange
);
chart.setPosition("D1");
chart.getTitle().setText("Organizational Hierarchy (3D Pyramid)");
chart.getLegend().setVisible(false);
}
Gráfico de colunas de pirâmide clusterizada
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Level", "2023", "2024"],
["Executive", 5, 6],
["Senior Management", 25, 28],
["Middle Management", 120, 135],
["Staff", 450, 480]
];
const dataRange = sheet.getRange("A1:C5");
dataRange.setValues(data);
// Create clustered pyramid column chart.
const chart = sheet.addChart(
ExcelScript.ChartType.pyramidColClustered,
dataRange
);
chart.setPosition("D1");
chart.getTitle().setText("Organizational Hierarchy by Year (Clustered 3D Pyramid)");
// Label the series with year names.
const seriesCollection = chart.getSeries();
seriesCollection[0].setName("2023");
seriesCollection[1].setName("2024");
chart.getLegend().setPosition(ExcelScript.ChartLegendPosition.bottom);
}
Gráfico de colunas de pirâmide empilhada
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Level", "2023", "2024"],
["Executive", 5, 6],
["Senior Management", 25, 28],
["Middle Management", 120, 135],
["Staff", 450, 480]
];
const dataRange = sheet.getRange("A1:C5");
dataRange.setValues(data);
// Create stacked pyramid column chart.
const chart = sheet.addChart(
ExcelScript.ChartType.pyramidColStacked,
dataRange
);
chart.setPosition("D1");
chart.getTitle().setText("Organizational Hierarchy by Year (Stacked 3D Pyramid)");
// Label the series with year names.
const seriesCollection = chart.getSeries();
seriesCollection[0].setName("2023");
seriesCollection[1].setName("2024");
chart.getLegend().setPosition(ExcelScript.ChartLegendPosition.bottom);
}
Gráfico de colunas em pirâmide 100% empilhada
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Level", "2023", "2024"],
["Executive", 5, 6],
["Senior Management", 25, 28],
["Middle Management", 120, 135],
["Staff", 450, 480]
];
const dataRange = sheet.getRange("A1:C5");
dataRange.setValues(data);
// Create 100% stacked pyramid column chart.
const chart = sheet.addChart(
ExcelScript.ChartType.pyramidColStacked100,
dataRange
);
chart.setPosition("D1");
chart.getTitle().setText("Organizational Hierarchy by Year (100% Stacked 3D Pyramid)");
// Label the series with year names.
const seriesCollection = chart.getSeries();
seriesCollection[0].setName("2023");
seriesCollection[1].setName("2024");
chart.getLegend().setPosition(ExcelScript.ChartLegendPosition.bottom);
}
Gráficos de barras cônicas
Gráfico de barras de cone clusterizado
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Quarter", "Target", "Achieved"],
["Q1", 100000, 95000],
["Q2", 120000, 125000],
["Q3", 130000, 128000],
["Q4", 150000, 158000]
];
const dataRange = sheet.getRange("A1:C5");
dataRange.setValues(data);
// Create clustered cone bar chart.
const chart = sheet.addChart(
ExcelScript.ChartType.coneBarClustered,
dataRange
);
chart.setPosition("D1");
chart.getTitle().setText("Quarterly Performance (Clustered 3D Cone Bar)");
chart.getLegend().setPosition(ExcelScript.ChartLegendPosition.bottom);
}
Gráfico de barras de cone empilhado
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Quarter", "Product Sales", "Services"],
["Q1", 65000, 35000],
["Q2", 70000, 55000],
["Q3", 68000, 60000],
["Q4", 72000, 86000]
];
const dataRange = sheet.getRange("A1:C5");
dataRange.setValues(data);
// Create stacked cone bar chart.
const chart = sheet.addChart(
ExcelScript.ChartType.coneBarStacked,
dataRange
);
chart.setPosition("D1");
chart.getTitle().setText("Quarterly Revenue by Source (Stacked 3D Cone Bar)");
chart.getLegend().setPosition(ExcelScript.ChartLegendPosition.bottom);
}
Gráfico de barras de cone 100% empilhado
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Quarter", "Product Sales", "Services"],
["Q1", 65000, 35000],
["Q2", 70000, 55000],
["Q3", 68000, 60000],
["Q4", 72000, 86000]
];
const dataRange = sheet.getRange("A1:C5");
dataRange.setValues(data);
// Create 100% stacked cone bar chart.
const chart = sheet.addChart(
ExcelScript.ChartType.coneBarStacked100,
dataRange
);
chart.setPosition("D1");
chart.getTitle().setText("Revenue Mix by Quarter (100% Stacked 3D Cone Bar)");
chart.getLegend().setPosition(ExcelScript.ChartLegendPosition.bottom);
}
Gráficos de barras cilíndricas
Gráfico de barras cilíndricas clusterizadas
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Product", "2023", "2024"],
["Laptops", 850, 920],
["Tablets", 720, 780],
["Phones", 640, 710],
["Monitors", 580, 650]
];
const dataRange = sheet.getRange("A1:C5");
dataRange.setValues(data);
// Create clustered cylinder bar chart.
const chart = sheet.addChart(
ExcelScript.ChartType.cylinderBarClustered,
dataRange
);
chart.setPosition("D1");
chart.getTitle().setText("Product Sales by Year (Clustered 3D Cylinder Bar)");
chart.getLegend().setPosition(ExcelScript.ChartLegendPosition.bottom);
}
Gráfico de barras cilíndricas empilhadas
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Product", "2023", "2024"],
["Laptops", 850, 920],
["Tablets", 720, 780],
["Phones", 640, 710],
["Monitors", 580, 650]
];
const dataRange = sheet.getRange("A1:C5");
dataRange.setValues(data);
// Create stacked cylinder bar chart.
const chart = sheet.addChart(
ExcelScript.ChartType.cylinderBarStacked,
dataRange
);
chart.setPosition("D1");
chart.getTitle().setText("Product Sales by Year (Stacked 3D Cylinder Bar)");
// Label the series with year names.
const seriesCollection = chart.getSeries();
seriesCollection[0].setName("2023");
seriesCollection[1].setName("2024");
chart.getLegend().setPosition(ExcelScript.ChartLegendPosition.bottom);
}
Gráfico de barras de cilindro 100% empilhado
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Product", "2023", "2024"],
["Laptops", 850, 920],
["Tablets", 720, 780],
["Phones", 640, 710],
["Monitors", 580, 650]
];
const dataRange = sheet.getRange("A1:C5");
dataRange.setValues(data);
// Create 100% stacked cylinder bar chart.
const chart = sheet.addChart(
ExcelScript.ChartType.cylinderBarStacked100,
dataRange
);
chart.setPosition("D1");
chart.getTitle().setText("Product Sales by Year (100% Stacked 3D Cylinder Bar)");
// Label the series with year names.
const seriesCollection = chart.getSeries();
seriesCollection[0].setName("2023");
seriesCollection[1].setName("2024");
chart.getLegend().setPosition(ExcelScript.ChartLegendPosition.bottom);
}
Gráficos de barras em pirâmide
Gráfico de barras de pirâmide clusterizada
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Level", "2023", "2024"],
["Executive", 5, 6],
["Senior Management", 25, 28],
["Middle Management", 120, 135],
["Staff", 450, 480]
];
const dataRange = sheet.getRange("A1:C5");
dataRange.setValues(data);
// Create clustered pyramid bar chart.
const chart = sheet.addChart(
ExcelScript.ChartType.pyramidBarClustered,
dataRange
);
chart.setPosition("D1");
chart.getTitle().setText("Organizational Hierarchy by Year (Clustered 3D Pyramid Bar)");
// Label the series with year names.
const seriesCollection = chart.getSeries();
seriesCollection[0].setName("2023");
seriesCollection[1].setName("2024");
chart.getLegend().setPosition(ExcelScript.ChartLegendPosition.bottom);
}
Gráfico de barras de pirâmide empilhada
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Level", "2023", "2024"],
["Executive", 5, 6],
["Senior Management", 25, 28],
["Middle Management", 120, 135],
["Staff", 450, 480]
];
const dataRange = sheet.getRange("A1:C5");
dataRange.setValues(data);
// Create stacked pyramid bar chart.
const chart = sheet.addChart(
ExcelScript.ChartType.pyramidBarStacked,
dataRange
);
chart.setPosition("D1");
chart.getTitle().setText("Organizational Hierarchy by Year (Stacked 3D Pyramid Bar)");
// Label the series with year names.
const seriesCollection = chart.getSeries();
seriesCollection[0].setName("2023");
seriesCollection[1].setName("2024");
chart.getLegend().setPosition(ExcelScript.ChartLegendPosition.bottom);
}
Gráfico de barras em pirâmide 100% empilhado
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Level", "2023", "2024"],
["Executive", 5, 6],
["Senior Management", 25, 28],
["Middle Management", 120, 135],
["Staff", 450, 480]
];
const dataRange = sheet.getRange("A1:C5");
dataRange.setValues(data);
// Create 100% stacked pyramid bar chart.
const chart = sheet.addChart(
ExcelScript.ChartType.pyramidBarStacked100,
dataRange
);
chart.setPosition("D1");
chart.getTitle().setText("Organizational Hierarchy by Year (100% Stacked 3D Pyramid Bar)");
// Label the series with year names.
const seriesCollection = chart.getSeries();
seriesCollection[0].setName("2023");
seriesCollection[1].setName("2024");
chart.getLegend().setPosition(ExcelScript.ChartLegendPosition.bottom);
}
Trabalhar com elementos do gráfico
Este exemplo demonstra como personalizar vários elementos de gráfico que se aplicam a todos os tipos de gráfico.
function main(workbook: ExcelScript.Workbook) {
const sheet = workbook.getActiveWorksheet();
// Add sample data.
const data = [
["Month", "Revenue", "Expenses"],
["Jan", 45000, 32000],
["Feb", 52000, 35000],
["Mar", 48000, 33000],
["Apr", 61000, 38000]
];
const dataRange = sheet.getRange("A1:C5");
dataRange.setValues(data);
// Create chart.
const chart = sheet.addChart(
ExcelScript.ChartType.columnClustered,
dataRange
);
chart.setPosition("E1");
// Customize chart title.
chart.getTitle().setText("Monthly Financial Overview");
const chartTitle = chart.getTitle();
chartTitle.getFormat().getFont().setSize(16);
chartTitle.getFormat().getFont().setBold(true);
chartTitle.getFormat().getFont().setColor("#2C3E50");
// Customize legend.
const legend = chart.getLegend();
legend.setPosition(ExcelScript.ChartLegendPosition.bottom);
legend.getFormat().getFont().setSize(10);
legend.setVisible(true);
// Customize axes.
const valueAxis = chart.getAxes().getValueAxis();
valueAxis.setDisplayUnit(ExcelScript.ChartAxisDisplayUnit.thousands);
valueAxis.getMajorGridlines().getFormat().getLine().setColor("#D3D3D3");
valueAxis.getTitle().setText("Amount (in thousands)");
const categoryAxis = chart.getAxes().getCategoryAxis();
categoryAxis.getTitle().setText("Month");
// Customize series.
const series = chart.getSeries();
series[0].getFormat().getFill().setSolidColor("#3498DB"); // Revenue - Blue.
series[1].getFormat().getFill().setSolidColor("#E74C3C"); // Expenses - Red.
// Set chart size.
chart.setHeight(300);
chart.setWidth(500);
}