`

Aspose.Words使用教程之从零创建OOXML图表

阅读更多

        文档类已经添加进了新的插入图表方法,所以,让我们看看如何使用DocumentBuilder.InsertChart方法将一个简单的列图表插入到文档。

如下所示:

 

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add chart with default data. You can specify different chart types and sizes.
Shape shape = builder.InsertChart(ChartType.Column, 432, 252);
// Chart property of Shape contains all chart related options.
Chart chart = shape.Chart;
// Get chart series collection.
ChartSeriesCollection seriesColl = chart.Series;
// Delete default generated series.
seriesColl.Clear();
// Create category names array, in this example we have two categories.
string[] categories = new string[] { "AW Category 1", "AW Category 2" };
// Adding new series. Please note, data arrays must not be empty and arrays must be the same size.
seriesColl.Add("AW Series 1", categories, new double[] { 1, 2 });
seriesColl.Add("AW Series 2", categories, new double[] { 3, 4 });
seriesColl.Add("AW Series 3", categories, new double[] { 5, 6 });
seriesColl.Add("AW Series 4", categories, new double[] { 7, 8 });
seriesColl.Add("AW Series 5", categories, new double[] { 9, 10 });
doc.Save(MyDir + @"TestInsertChartColumn.docx");

 

Dim doc As New Document()
Dim builder As New DocumentBuilder(doc)
' Add chart with default data. You can specify different chart types and sizes.
Dim shape As Shape = builder.InsertChart(ChartType.Column, 432, 252)
' Chart property of Shape contains all chart related options.
Dim chart As Chart = shape.Chart
' Get chart series collection.
Dim seriesColl As ChartSeriesCollection = chart.Series
' Delete default generated series.
seriesColl.Clear()
' Create category names array, in this example we have two categories.
Dim categories() As String = {"AW Category 1", "AW Category 2"}
' Adding new series. Please note, data arrays must not be empty and arrays must be the same size.
seriesColl.Add("AW Series 1", categories, New Double() {1, 2})
seriesColl.Add("AW Series 2", categories, New Double() {3, 4})
seriesColl.Add("AW Series 3", categories, New Double() {5, 6})
seriesColl.Add("AW Series 4", categories, New Double() {7, 8})
seriesColl.Add("AW Series 5", categories, New Double() {9, 10})
doc.Save(MyDir & "TestInsertChartColumn.docx")

这段代码会产生如下结果:

Aspose.Words

有四种不同的加载添加方法:

1.插入列图表
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert Column chart.
Shape shape = builder.InsertChart(ChartType.Column, 432, 252);
Chart chart = shape.Chart;
// Use this overload to add series to any type of Bar, Column, Line and Surface charts.
chart.Series.Add("AW Series 1", new string[] { "AW Category 1", "AW Category 2" }, new double[] { 1, 2 });
doc.Save(MyDir + @"TestInsertColumnChart.docx");
Dim doc As New Document()
Dim builder As New DocumentBuilder(doc)
' Insert Column chart.
Dim shape As Shape = builder.InsertChart(ChartType.Column, 432, 252)
Dim chart As Chart = shape.Chart
' Use this overload to add series to any type of Bar, Column, Line and Surface charts.
chart.Series.Add("AW Series 1", New string() { "AW Category 1", "AW Category 2" }, New Double() { 1, 2 })
doc.Save(MyDir & "TestInsertColumnChart.docx")

 

结果如下:

Aspose.Words

2.插入散点图

 

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert Scatter chart.
Shape shape = builder.InsertChart(ChartType.Scatter, 432, 252);
Chart chart = shape.Chart;
// Use this overload to add series to any type of Scatter charts.
chart.Series.Add("AW Series 1", new double[] { 0.7, 1.8, 2.6 }, new double[] { 2.7, 3.2, 0.8 });
doc.Save(MyDir + @"TestInsertScatterChart.docx");

 

Dim doc As New Document()
Dim builder As New DocumentBuilder(doc)
' Insert Scatter chart.
Dim shape As Shape = builder.InsertChart(ChartType.Scatter, 432, 252)
Dim chart As Chart = shape.Chart
' Use this overload to add series to any type of Scatter charts.
chart.Series.Add("AW Series 1", New Double() {0.7, 1.8, 2.6}, New Double() {2.7, 3.2, 0.8})
doc.Save(MyDir & "TestInsertScatterChart.docx")

 

结果如下:

Aspose.Words

3.插入面积图

 

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert Area chart.
Shape shape = builder.InsertChart(ChartType.Area, 432, 252);
Chart chart = shape.Chart;
// Use this overload to add series to any type of Area, Radar and Stock charts.
chart.Series.Add("AW Series 1", new DateTime[] { 
new DateTime(2002, 05, 01), 
new DateTime(2002, 06, 01),
new DateTime(2002, 07, 01),
new DateTime(2002, 08, 01),
new DateTime(2002, 09, 01)}, new double[] { 32, 32, 28, 12, 15 });
doc.Save(MyDir + @"TestInsertAreaChart.docx");
Dim doc As New Document()
Dim builder As New DocumentBuilder(doc)
' Insert Area chart.
Dim shape As Shape = builder.InsertChart(ChartType.Area, 432, 252)
Dim chart As Chart = shape.Chart
' Use this overload to add series to any type of Area, Radar and Stock charts.
chart.Series.Add("AW Series 1", New DateTime() {New DateTime(2002, 5, 1), New DateTime(2002, 6, 1), New DateTime(2002, 7, 1), New DateTime(2002, 8, 1), New DateTime(2002, 9, 1)}, New Double() {32, 32, 28, 12, 15})
doc.Save(MyDir & "TestInsertAreaChart.docx")

 

结果如下:

Aspose.Words

4.插入气泡式图表

 

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert Bubble chart.
Shape shape = builder.InsertChart(ChartType.Bubble, 432, 252);
Chart chart = shape.Chart;
// Use this overload to add series to any type of Bubble charts.
chart.Series.Add("AW Series 1", new double[] { 0.7, 1.8, 2.6 }, new double[] { 2.7, 3.2, 0.8 }, new double[] { 10, 4, 8 });
doc.Save(MyDir + @"TestInsertBubbleChart.docx");

 

Dim doc As New Document()
Dim builder As New DocumentBuilder(doc)
' Insert Bubble chart.
Dim shape As Shape = builder.InsertChart(ChartType.Bubble, 432, 252)
Dim chart As Chart = shape.Chart
' Use this overload to add series to any type of Bubble charts.
chart.Series.Add("AW Series 1", New Double() {0.7, 1.8, 2.6}, New Double() {2.7, 3.2, 0.8}, New Double() {10, 4, 8})
doc.Save(MyDir & "TestInsertBubbleChart.docx")

 

结果如下:

Aspose.Words
0
1
分享到:
评论

相关推荐

    Aspose.Words使用教程之插入文档元素(二)

    "Aspose.Words使用教程之插入文档元素(二)" 本教程将详细介绍Aspose.Words的插入文档元素的相关知识点,包括插入一个间断、插入一个图像和插入一个书签等。 一、插入一个间断 在Aspose.Words中,可以使用...

    Aspose.Words_生成excel_aspose.word_生成word_aspose.words_

    虽然Aspose.Words主要用于处理Word文档,但通过Aspose.Cells,两者可以结合使用,实现从Word文档中提取数据并将其格式化为Excel表格,或者将Excel数据导入Word文档中,生成报表或合并信件。这种结合使用方式在数据...

    【连载】Aspose.Words使用教程之插入文档元素(一)

    ### Aspose.Words 使用教程之插入文档元素(一) #### 插入文本的字符串 在Aspose.Words中,为了向文档中插入文本,我们主要使用`DocumentBuilder.Write`方法。这种方法不仅简单直接,而且非常灵活,允许用户指定...

    Aspose.Words根据word模板写入数据和图表(chart)

    在本文中,我们将深入探讨如何使用Aspose.Words根据Word模板写入数据和插入图表,特别是饼形图和柱形图。 首先,理解模板替换的基础是关键。Aspose.Words支持通过使用书签或域来定义模板中的可替换区域。在模板文档...

    Aspose.Words帮助API

    通过Aspose.Words for .NET Documentation,开发者可以详细学习API的用法,包括详细的API参考、示例代码和教程,以便更好地理解和应用Aspose.Words的功能。无论是个人开发者还是企业团队,Aspose.Words都是进行文档...

    Aspose.Words.Cpp_18.11.zip

    Aspose.Words是一款强大的文档处理库,主要用于在C++编程环境中创建、操作和转换Microsoft Word文档。这个"Aspose.Words.Cpp_18.11.zip"压缩包包含的资源显然是Aspose.Words库的C++版本,版本号为18.11,允许开发者...

    最新 Aspose.Words20181113

    最新 Aspose.Words20181113最新 Aspose.Words20181113最新 Aspose.Words20181113最新 Aspose.Words20181113最新 Aspose.Words20181113最新 Aspose.Words20181113最新 Aspose.Words20181113最新 Aspose.Words20181113...

    利用Aspose.words .ZedGraph 生成折线图 报表

    3. 在Aspose.Words中插入图像:打开或创建Word文档,定位到需要插入图表的位置,使用Aspose.Words的API插入图像,例如`DocumentBuilder.InsertImage()`方法。 4. 自动化报表生成:如果需要批量生成报表,可以将以上...

    Aspose.Words for NET根据word模板创建文档Demo源码

    Aspose.Words是一款强大的.NET库,它允许开发者在没有安装Microsoft Word的情况下,对Word文档进行创建、编辑和格式化操作。这款库提供了丰富的API,使得处理Word文档变得简单且高效。在“Aspose.Words for .NET根据...

    Aspose.Words 18.7 带SkiaSharp 解决了错误 net 和netcore 版本

    Aspose.Words是一款著名的文档处理库,用于在.NET和.NET Core平台上创建、编辑和操作Microsoft Word文档。在Aspose.Words 18.7版本中,引入了SkiaSharp的集成,这是一个强大的2D图形处理库,为解决特定的错误和问题...

    Aspose.Words.dll(4个版本).rar

    4个版本的Aspose.words.dll,包括 Aspose.Words.V16.7,Aspose.Words.V17.12,Aspose.Words.V18.4,AsposeWords.V18.7,修复一些低版本bug

    Aspose.Words for .NET 18.7(.net+.net core) 去水印,学习使用

    Aspose.Words for .NET 18.7是一款强大的文档处理库,专为.NET和.NET Core框架设计,用于在各种应用程序中实现高级文档操作,包括创建、编辑、转换和渲染Microsoft Word文档。在这个版本中,重点是去水印功能,这...

    Aspose.Words For .Net18.7(包括core版本)下载

    Aspose.Words是一款强大的文档处理库,专为.NET开发者设计,用于在应用程序中创建、编辑、转换和显示Microsoft Word文档。这个版本是18.7,涵盖了Core版本,这意味着它支持.NET Core框架,使得跨平台开发变得更加...

    Aspose.Cells.dll Aspose.Slides.dll Aspose.Words.dll 三合一无限制版本

    在这个“Aspose.Cells.dll Aspose.Slides.dll Aspose.Words.dll 三合一无限制版本”中,我们讨论的是Aspose针对.NET平台的三个核心组件: 1. **Aspose.Cells.dll**: 这是Aspose为.NET提供的电子表格处理组件。它...

    aspose.words操作word 一些关键方法

    在IT行业中,Aspose.Words是一款非常强大的文档处理组件,它允许开发者在不依赖Microsoft Office的情况下,进行Word文档的创建、阅读、修改和转换。这个资源聚焦于利用Aspose.Words进行一系列的关键操作,包括插入...

    Aspose.words 实现插入文件,页面设置,替换 表格操作,分页等

    Aspose.Words是一款强大的文档处理库,用于在.NET环境中创建、编辑、转换和显示Microsoft Word文档。本篇文章将深入探讨Aspose.Words如何实现插入文件、页面设置、文本替换、表格操作以及分页等核心功能。 1. 插入...

    Aspose.Words 19.11(.net core 可用)

    Aspose.Words是一款强大的文档处理库,主要用于在.NET Core环境下创建、编辑和转换Microsoft Word文档。这个19.11版本特别引人注目,因为它兼容.NET Core 3.1框架,这意味着开发者可以在跨平台环境中利用这个库的...

    Unity创建表格Aspose.Words插件和system.drawing插入图片

    本主题将探讨如何利用Aspose.Words和System.Drawing这两个组件在Unity中创建丰富的Word文档,包括插入表格和图片。 Aspose.Words是一款强大的.NET库,它允许程序员在不依赖Microsoft Word的情况下操作Word文档。在...

    Aspose.Words和Aspose.Pdf的dll文件.rar

    Aspose.Words和Aspose.Pdf是两个知名的第三方库,广泛应用于.NET开发环境中,用于处理Microsoft Office文档和PDF文件。这两个DLL文件是这些库的组件,允许开发者在C#项目中进行集成,实现文档格式之间的转换。 ...

    Aspose.Words18.7破解版.rar

    Aspose.Words.dll18.7破解版 亲测可用 我的项目用的是.net framework4.0框架,用Aspose.Words.dll实现在线word预览。亲测可用!

Global site tag (gtag.js) - Google Analytics