通过Shape.Chart对象处理图表
Contents
[
Hide
]
一旦图表被插入并填充了数据,您就可以改变它的外观。 Shape.Chart
属性包含通过公共API提供的所有图表相关选项。
例如,让我们更改图表标题或图例行为:
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-words/Aspose.Words-for-C | |
// The path to the documents directory. | |
System::String outputDataDir = GetOutputDataDir_WorkingWithCharts(); | |
System::SharedPtr<Document> doc = System::MakeObject<Document>(); | |
System::SharedPtr<DocumentBuilder> builder = System::MakeObject<DocumentBuilder>(doc); | |
System::SharedPtr<Shape> shape = builder->InsertChart(ChartType::Line, 432, 252); | |
System::SharedPtr<Chart> chart = shape->get_Chart(); | |
// Determines whether the title shall be shown for this chart. Default is true. | |
chart->get_Title()->set_Show(true); | |
// Setting chart Title. | |
chart->get_Title()->set_Text(u"Sample Line Chart Title"); | |
// Determines whether other chart elements shall be allowed to overlap title. | |
chart->get_Title()->set_Overlay(false); | |
// Please note if null or empty value is specified as title text, auto generated title will be shown. | |
// Determines how legend shall be shown for this chart. | |
chart->get_Legend()->set_Position(LegendPosition::Left); | |
chart->get_Legend()->set_Overlay(true); | |
System::String outputPath = outputDataDir + u"CreateChartUsingShape.docx"; | |
doc->Save(outputPath); |
代码生成如下结果: