طريقة سهلة لإعداد المخطط باستخدام طريقة Chart.SetChartDataRange
Contents
[
Hide
]
Aspose.Cells يوفر الآنChart.SetChartDataRange () طريقة إعداد الرسم البياني بسهولة. باستخدام هذه الطريقة ، لن تحتاج الآن إلى إضافة بيانات محور السلسلة والفئة بشكل منفصل.
يشرح نموذج التعليمات البرمجية التالي الاستخدامChart.SetChartDataRange ()طريقة إعداد الرسم البياني بسهولة.
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); |