C++ ile Excel Grafiklerinin Eksenlerini Yönetme
Contents
[
Hide
]
Excel grafiklerinde 3 çeşit eksen bulunmaktadır:
- Yatay (Kategori) Eksen : X Eksen
- Dikey (Değer) Eksen : Y Eksen
- Derinlik (Seri) Eksen : Z Eksen
Eksen Seçenekleri
Aspose.Cells ayrıca çalışma zamanında grafik eksenlerini yönetmenize olanak tanır. Eksen nesnesi kullanarak, Excel’deki gibi tüm Eksen seçeneklerini değiştirebilirsiniz.
||
X ve Y Eksenlerini Yönetme
Excel grafiklerinde, yatay ve dikey eksenler en sık kullanılan iki eksendir.
Aşağıdaki kod parçacığı, X ve Y eksenlerinin ayarlarını nasıl yapacağınızı gösterir.
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
using namespace Aspose::Cells::Charts;
int main()
{
Aspose::Cells::Startup();
// Instantiating a Workbook object
Workbook 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(u"A1").PutValue(u"Series1");
worksheet.GetCells().Get(u"A2").PutValue(50);
worksheet.GetCells().Get(u"A3").PutValue(100);
worksheet.GetCells().Get(u"A4").PutValue(150);
worksheet.GetCells().Get(u"B1").PutValue(u"Series2");
worksheet.GetCells().Get(u"B2").PutValue(60);
worksheet.GetCells().Get(u"B3").PutValue(32);
worksheet.GetCells().Get(u"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 "B4"
chart.SetChartDataRange(u"A1:B4", true);
// Hiding X axis
chart.GetCategoryAxis().SetIsVisible(false);
// Setting max value of Y axis
chart.GetValueAxis().SetMaxValue(200);
// Setting major unit
chart.GetValueAxis().SetMajorUnit(50);
// Save the file
workbook.Save(u"chart_axes.xlsx");
Aspose::Cells::Cleanup();
}