Méthode simple pour la configuration du graphique à l'aide de la méthode Chart.SetChartDataRange
Contents
[
Hide
]
Aspose.Cells fournit maintenantGraphique.SetChartDataRange() méthode pour configurer facilement le graphique. En utilisant cette méthode, vous n’aurez plus besoin d’ajouter séparément les données de l’axe des séries et des catégories.
L’exemple de code suivant explique l’utilisationGraphique.SetChartDataRange()méthode pour configurer facilement le graphique.
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-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create new workbook | |
Workbook workbook = new Workbook(FileFormatType.Xlsx); | |
// Access first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Add data for chart | |
// Category Axis Values | |
worksheet.Cells["A2"].PutValue("C1"); | |
worksheet.Cells["A3"].PutValue("C2"); | |
worksheet.Cells["A4"].PutValue("C3"); | |
// First vertical series | |
worksheet.Cells["B1"].PutValue("T1"); | |
worksheet.Cells["B2"].PutValue(6); | |
worksheet.Cells["B3"].PutValue(3); | |
worksheet.Cells["B4"].PutValue(2); | |
// Second vertical series | |
worksheet.Cells["C1"].PutValue("T2"); | |
worksheet.Cells["C2"].PutValue(7); | |
worksheet.Cells["C3"].PutValue(2); | |
worksheet.Cells["C4"].PutValue(5); | |
// Third vertical series | |
worksheet.Cells["D1"].PutValue("T3"); | |
worksheet.Cells["D2"].PutValue(8); | |
worksheet.Cells["D3"].PutValue(4); | |
worksheet.Cells["D4"].PutValue(2); | |
// Create Column chart with easy way | |
int idx = worksheet.Charts.Add(ChartType.Column, 6, 5, 20, 13); | |
Chart ch = worksheet.Charts[idx]; | |
ch.SetChartDataRange("A1:D4", true); | |
// Save the workbook | |
workbook.Save(dataDir + "output_out.xlsx", SaveFormat.Xlsx); |