Legende von Excel Diagrammen verwalten
Contents
[
Hide
]
Legendenoptionen
Aspose.Cells ermöglicht es auch, die Legende des Diagramms zur Laufzeit zu verwalten, mit dem Legende-Objekt, die Legende kann verschoben, aktualisiert und formatiert werden.
||
Festlegen der Legende des Diagramms
Es ist einfach, die Legende des Diagramms mit Aspose.Cells Legend zu verwalten.
Der folgende Codeausschnitt zeigt, wie die Legende verwaltet wird:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
// Move the legend to left | |
chart.getLegend().setPosition(LegendPositionType.LEFT); | |
// Set font color of the legend | |
chart.getLegend().getFont().setColor(Color.getBlue()); | |
// Save the file | |
workbook.save("chart_datalabels.xlsx"); |