用C++设置图表的数据显示标签的形状类型
Contents
[
Hide
]
可能的使用场景
你可以使用DataLabels.ShapeType
属性更改图表数据标签的形状类型。它接受DataLabelShapeType
枚举的值,根据需要更改数据标签的形状。部分值包括:
DataLabelShapeType.BentLineCallout
DataLabelShapeType.DownArrowCallout
DataLabelShapeType.Ellipse
DataLabelShapeType.LineCallout
DataLabelShapeType.Rect
etc.
设置图表数据标签的形状类型
以下示例代码将图表数据标签的形状类型更改为DataLabelShapeType.WedgeEllipseCallout
。请参阅此代码使用的示例Excel文件和由其生成的输出Excel文件。截屏展示了代码在示例Excel文件上的效果。
示例代码
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
using namespace Aspose::Cells::Charts;
int main()
{
Aspose::Cells::Startup();
// Load source Excel file
U16String inputFilePath = u"sampleSetShapeTypeOfDataLabelsOfChart.xlsx";
Workbook wb(inputFilePath);
// Access first worksheet
Worksheet ws = wb.GetWorksheets().Get(0);
// Access first chart
Chart ch = ws.GetCharts().Get(0);
// Access first series
Series srs = ch.GetNSeries().Get(0);
// Set the shape type of data labels i.e. Speech Bubble Oval
srs.GetDataLabels().SetShapeType(DataLabelShapeType::WedgeEllipseCallout);
// Save the output Excel file
U16String outputFilePath = u"outputSetShapeTypeOfDataLabelsOfChart.xlsx";
wb.Save(outputFilePath);
std::cout << "Shape type of data labels set successfully!" << std::endl;
Aspose::Cells::Cleanup();
}