Forma sencilla de configurar el gráfico usando el método Chart.setChartDataRange
Contents
[
Hide
]
Aspose.Cells ahora proporciona el método Chart.setChartDataRange() para configurar el gráfico fácilmente. Usando este método, ya no necesitará agregar las series y los datos del eje de categoría por separado.
Forma sencilla de configurar el gráfico usando el método Chart.setChartDataRange
El siguiente código de ejemplo explica el uso de Chart.setChartDataRange() para configurar fácilmente el gráfico.
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
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(EasyWayForChartSetup.class); | |
// Create new workbook | |
Workbook workbook = new Workbook(FileFormatType.XLSX); | |
// Access first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Add data for chart | |
// Category Axis Values | |
worksheet.getCells().get("A2").putValue("C1"); | |
worksheet.getCells().get("A3").putValue("C2"); | |
worksheet.getCells().get("A4").putValue("C3"); | |
// First vertical series | |
worksheet.getCells().get("B1").putValue("T1"); | |
worksheet.getCells().get("B2").putValue(6); | |
worksheet.getCells().get("B3").putValue(3); | |
worksheet.getCells().get("B4").putValue(2); | |
// Second vertical series | |
worksheet.getCells().get("C1").putValue("T2"); | |
worksheet.getCells().get("C2").putValue(7); | |
worksheet.getCells().get("C3").putValue(2); | |
worksheet.getCells().get("C4").putValue(5); | |
// Third vertical series | |
worksheet.getCells().get("D1").putValue("T3"); | |
worksheet.getCells().get("D2").putValue(8); | |
worksheet.getCells().get("D3").putValue(4); | |
worksheet.getCells().get("D4").putValue(2); | |
// Create Column chart with easy way | |
int idx = worksheet.getCharts().add(ChartType.COLUMN, 6, 5, 20, 13); | |
Chart ch = worksheet.getCharts().get(idx); | |
ch.setChartDataRange("A1:D4", true); | |
// Save the workbook | |
workbook.save(dataDir + "output.xlsx", SaveFormat.XLSX); |