Gestisci le etichette dati dei grafici di Excel

Opzioni DataLabels

Aspose.Cells consente anche di gestire le etichette dati del grafico in fase di esecuzione , conEtichette dati oggetto, è semplice spostare, aggiornare e formattare le etichette dati del grafico.

|cose da fare:immagine_alt_testo|

Gestisci le etichette dati del grafico

È semplice gestire le etichette dati del grafico con Aspose.CellsEtichette dati.

Il seguente frammento di codice mostra come gestire i DataLabel:

// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Adding a new worksheet to the Workbook object
int sheetIndex = workbook.getWorksheets().add();
// Obtaining the reference of the newly added worksheet by passing its sheet index
Worksheet worksheet = workbook.getWorksheets().get(sheetIndex);
// Adding sample values to cells
worksheet.getCells().get("A1").putValue("Series1");
worksheet.getCells().get("A2").putValue(50);
worksheet.getCells().get("A3").putValue(100);
worksheet.getCells().get("A4").putValue(150);
worksheet.getCells().get("B1").putValue("Series2");
worksheet.getCells().get("B2").putValue(60);
worksheet.getCells().get("B3").putValue(32);
worksheet.getCells().get("B4").putValue(50);
// Adding a chart to the worksheet
int chartIndex = worksheet.getCharts().add(ChartType.COLUMN, 5, 0, 15, 5);
// Accessing the instance of the newly added chart
Chart 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(LabelPositionType.CENTER);
// Save the file
workbook.save("chart_datalabels.xlsx");

Argomenti avanzati