Gestionar las etiquetas de datos (DataLabels) de gráficos de Excel con Node.js via C++
Podemos conocer fácilmente el valor, el porcentaje, etc. de cada serie
Opciones de etiquetas de datos
Aspose.Cells for Node.js via C++ también permite gestionar las etiquetas de datos del gráfico en tiempo de ejecución, con el objeto DataLabels, es sencillo mover, actualizar y formatear las etiquetas de datos del gráfico.
||
Administrar las etiquetas de datos del gráfico
Es simple gestionar las etiquetas de datos del gráfico con Aspose.Cells DataLabels.
El siguiente fragmento de código demuestra cómo gestionar DataLabels.
const AsposeCells = require("aspose.cells.node");
const path = require("path");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "sample.xlsx");
// Instantiating a Workbook object
const workbook = new AsposeCells.Workbook();
// Adding a new worksheet to the Workbook object
const sheetIndex = workbook.getWorksheets().add();
// Obtaining the reference of the newly added worksheet by passing its sheet index
const worksheet = workbook.getWorksheets().get(sheetIndex);
// Adding sample values to cells
worksheet.getCells().get("A1").putValue(50);
worksheet.getCells().get("A2").putValue(100);
worksheet.getCells().get("A3").putValue(150);
worksheet.getCells().get("B1").putValue(60);
worksheet.getCells().get("B2").putValue(32);
worksheet.getCells().get("B3").putValue(50);
// Adding a chart to the worksheet
const chartIndex = worksheet.getCharts().add(AsposeCells.ChartType.Column, 5, 0, 15, 5);
// Accessing the instance of the newly added chart
const chart = worksheet.getCharts().get(chartIndex);
// Adding SeriesCollection (chart data source) to the chart ranging from "A1" cell to "B3"
chart.getNSeries().add("A1:B3", true);
// Show value labels
chart.getNSeries().get(0).getDataLabels().setShowValue(true);
// Show series name labels
chart.getNSeries().get(1).getDataLabels().setShowSeriesName(true);
// Move labels to center
chart.getNSeries().get(1).getDataLabels().setPosition(AsposeCells.LabelPositionType.Center);
// Save the file
workbook.save("chart_datalabels.xlsx");
Temas avanzados
- Agregar etiquetas personalizadas a los puntos de datos en la serie del gráfico
- Deshabilitar el ajuste de texto para las etiquetas de datos del gráfico
- Redimensionar la forma de la etiqueta de datos del gráfico para que se ajuste al texto
- Etiqueta de datos personalizada de texto enriquecido del punto del gráfico
- Establecer el tipo de forma de las etiquetas de datos del gráfico
- Mostrar el rango de celdas como las etiquetas de datos