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);
該代碼產生如下結果: