Aspose.Words for C++使用教程:从Scratch创建OOXML图表(下)

Aspose.Words for C++不依赖Microsoft Word,可在任何C++应用程序中生成和操作Word格式文档。本文将与大家分享如何插入散点图、面积图和气泡图到文档中。

 

Aspose.Words for C++icon-default.png?t=M7J4https://www.evget.com/product/4114提供了 InsertChart 方法,该方法已添加到 DocumentBuilder 类中。那么,让我们看看如何使用 DocumentBuilder-> InsertChart 方法将简单的图表插入到文档中:

如何插入散点图

下面的示例显示了如何插入散点图。

// The path to the documents directory.
System::String dataDir = GetDataDir_WorkingWithCharts();
System::SharedPtr doc = System::MakeObject();
System::SharedPtr builder = System::MakeObject(doc);

// Insert Scatter chart.
System::SharedPtr shape = builder->InsertChart(ChartType::Scatter, 432, 252);
System::SharedPtr chart = shape->get_Chart();

// Use this overload to add series to any type of Scatter charts.
chart->get_Series()->Add(u"AW Series 1", System::MakeArray({0.7, 1.8, 2.6}), System::MakeArray({2.7, 3.2, 0.8}));

System::String outputPath = dataDir + GetOutputFilePath(u"InsertScatterChart.docx");
doc->Save(outputPath);

该代码产生以下结果: 

 

如何插入面积图。

下面的示例显示了如何插入散点图。

// The path to the documents directory.
System::String dataDir = GetDataDir_WorkingWithCharts();
System::SharedPtr doc = System::MakeObject();
System::SharedPtr builder = System::MakeObject(doc);

// Insert Area chart.
System::SharedPtr shape = builder->InsertChart(ChartType::Area, 432, 252);
System::SharedPtr chart = shape->get_Chart();

// Use this overload to add series to any type of Area, Radar and Stock charts.
chart->get_Series()->Add(u"AW Series 1",
                         System::MakeArray({System::DateTime(2002, 5, 1), System::DateTime(2002, 6, 1), System::DateTime(2002, 7, 1), System::DateTime(2002, 8, 1), System::DateTime(2002, 9, 1)}),
                         System::MakeArray({32, 32, 28, 12, 15}));
System::String outputPath = dataDir + GetOutputFilePath(u"InsertAreaChart.docx");
doc->Save(outputPath);

该代码产生以下结果:

如何插入气泡图。

下面的示例显示了如何插入气泡图。

// The path to the documents directory.
System::String dataDir = GetDataDir_WorkingWithCharts();
System::SharedPtr doc = System::MakeObject();
System::SharedPtr builder = System::MakeObject(doc);

// Insert Bubble chart.
System::SharedPtr shape = builder->InsertChart(ChartType::Bubble, 432, 252);
System::SharedPtr chart = shape->get_Chart();

// Use this overload to add series to any type of Bubble charts.
chart->get_Series()->Add(u"AW Series 1",
                         System::MakeArray({0.7, 1.8, 2.6}),
                         System::MakeArray({2.7, 3.2, 0.8}),
                         System::MakeArray({10, 4, 8}));
System::String outputPath = dataDir + GetOutputFilePath(u"InsertBubbleChart.docx");
doc->Save(outputPath);

该代码产生以下结果:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值