Aspose.Words For .Net是一种高级Word文档处理API,用于执行各类文档管理和操做任务。API支持生成,修改,转换,呈现和打印文档,而无需在跨平台应用程序中直接使用Microsoft Word。此外,API支持全部流行的Word处理文件格式,并容许将Word文档导出或转换为固定布局文件格式和最经常使用的图像/多媒体格式。布局
接下来咱们进入关于“使用图表”的介绍,在Aspose.Words中学会从头开始建立OOXML图表,包括柱状图、散点图、面积图和睦泡图。ui
(若是您想下载Aspose.Words或了解正版价格,请随时加入Aspose技术交流群(642018183)。)this
插入柱形图 spa
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; // Check series count. Console.WriteLine(seriesColl.Count); // 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 }); dataDir = dataDir + @"TestInsertSimpleChartColumn_out.doc"; doc.Save(dataDir);
该代码产生如下结果:blog
添加方法有四种不一样的重载,能够覆盖全部图表类型的数据源的全部可能变体:ci
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 }); dataDir = dataDir + @"TestInsertChartColumn_out.doc"; doc.Save(dataDir);
该代码产生如下结果:文档
插入散点图string
// The path to the documents directory. string dataDir = RunExamples.GetDataDir_WorkingWithCharts(); 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 }); dataDir = dataDir + "TestInsertScatterChart_out.docx"; doc.Save(dataDir);
该代码产生如下结果:it
插入面积图io
// The path to the documents directory. string dataDir = RunExamples.GetDataDir_WorkingWithCharts(); 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 }); dataDir = dataDir + @"TestInsertAreaChart_out.docx"; doc.Save(dataDir);
该代码产生如下结果:
插入气泡图
// The path to the documents directory. string dataDir = RunExamples.GetDataDir_WorkingWithCharts(); 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 }); dataDir = dataDir + @"TestInsertBubbleChart_out.docx"; doc.Save(dataDir);
该代码产生如下结果: