翻譯|使用教程|編輯:李顯亮|2019-12-10 09:36:26.420|閱讀 963 次
概述:本文將進入關于“使用圖表”的介紹,在Aspose.Words中學會如何設置圖表軸屬性,包括設置軸的日期時間值、設置軸的界限、在標簽之間設置間隔單位、隱藏圖表軸和對齊圖表標簽。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Aspose.Words For .Net是一種高級Word文檔處理API,用于執行各種文檔管理和操作任務。API支持生成,修改,轉換,呈現和打印文檔,而無需在跨平臺應用程序中直接使用Microsoft Word。此外,API支持所有流行的Word處理文件格式,并允許將Word文檔導出或轉換為固定布局文件格式和最常用的圖像/多媒體格式。
接下來我們將進入關于“使用圖表”的介紹,在Aspose.Words中學會如何設置圖表軸屬性,包括設置軸的日期時間值、設置軸的界限、在標簽之間設置間隔單位、隱藏圖表軸和對齊圖表標簽。
>>Aspose.Words for .NET更新至最新版v19.12,支持轉換為PDF 1.7標準,點擊下載體驗
如何設置圖表軸屬性
如果要使用圖表軸,縮放比例和值軸的顯示單位,請使用ChartAxis,AxisDisplayUnit和AxisScaling類。下面給出的代碼示例顯示了如何定義X和Y軸屬性。
Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Insert chart. Shape shape = builder.InsertChart(ChartType.Area, 432, 252); Chart chart = shape.Chart; // Clear demo data. chart.Series.Clear(); // Fill data. chart.Series.Add("AW Series 1", new DateTime[] { new DateTime(2002, 01, 01), new DateTime(2002, 06, 01), new DateTime(2002, 07, 01), new DateTime(2002, 08, 01), new DateTime(2002, 09, 01) }, new double[] { 640, 320, 280, 120, 150 }); ChartAxis xAxis = chart.AxisX; ChartAxis yAxis = chart.AxisY; // Change the X axis to be category instead of date, so all the points will be put with equal interval on the X axis. xAxis.CategoryType = AxisCategoryType.Category; // Define X axis properties. xAxis.Crosses = AxisCrosses.Custom; xAxis.CrossesAt = 3; // measured in display units of the Y axis (hundreds) xAxis.ReverseOrder = true; xAxis.MajorTickMark = AxisTickMark.Cross; xAxis.MinorTickMark = AxisTickMark.Outside; xAxis.TickLabelOffset = 200; // Define Y axis properties. yAxis.TickLabelPosition = AxisTickLabelPosition.High; yAxis.MajorUnit = 100; yAxis.MinorUnit = 50; yAxis.DisplayUnit.Unit = AxisBuiltInUnit.Hundreds; yAxis.Scaling.Minimum = new AxisBound(100); yAxis.Scaling.Maximum = new AxisBound(700); dataDir = dataDir + @"SetAxisProperties_out.docx"; doc.Save(dataDir);
還想要更多嗎?您可以點擊閱讀【2019 · Aspose最新資源整合】,查找需要的教程資源。讓人興奮的是Aspose.Total限時直降10000元!java版另送IDE開發工具一套!立馬1分鐘了解全部咨詢!
如何設置軸的日期時間值
以下代碼示例顯示如何為軸屬性設置日期/時間值。
Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Insert chart. Shape shape = builder.InsertChart(ChartType.Column, 432, 252); Chart chart = shape.Chart; // Clear demo data. chart.Series.Clear(); // Fill data. chart.Series.Add("AW Series 1", new DateTime[] { new DateTime(2017, 11, 06), new DateTime(2017, 11, 09), new DateTime(2017, 11, 15), new DateTime(2017, 11, 21), new DateTime(2017, 11, 25), new DateTime(2017, 11, 29) }, new double[] { 1.2, 0.3, 2.1, 2.9, 4.2, 5.3 }); // Set X axis bounds. ChartAxis xAxis = chart.AxisX; xAxis.Scaling.Minimum = new AxisBound((new DateTime(2017, 11, 05)).ToOADate()); xAxis.Scaling.Maximum = new AxisBound((new DateTime(2017, 12, 03)).ToOADate()); // Set major units to a week and minor units to a day. xAxis.MajorUnit = 7; xAxis.MinorUnit = 1; xAxis.MajorTickMark = AxisTickMark.Cross; xAxis.MinorTickMark = AxisTickMark.Outside; dataDir = dataDir + @"SetDateTimeValuesToAxis_out.docx"; doc.Save(dataDir);
doc.Save(dataDir);
如何設置軸的界限
AxisBound類表示軸值的最小或最大范圍。綁定可以指定為數字,日期時間或特殊的“自動”值。以下代碼示例顯示如何設置軸的邊界。
Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Insert chart. Shape shape = builder.InsertChart(ChartType.Column, 432, 252); Chart chart = shape.Chart; // Clear demo data. chart.Series.Clear(); // Fill data. chart.Series.Add("AW Series 1", new string[] { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" }, new double[] { 1.2, 0.3, 2.1, 2.9, 4.2 }); chart.AxisY.Scaling.Minimum = new AxisBound(0); chart.AxisY.Scaling.Maximum = new AxisBound(6); dataDir = dataDir + @"SetboundsOfAxis_out.docx"; doc.Save(dataDir);
如何在標簽之間設置間隔單位
下面的代碼示例演示如何設置軸上標簽之間的間隔單位。
Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Insert chart. Shape shape = builder.InsertChart(ChartType.Column, 432, 252); Chart chart = shape.Chart; // Clear demo data. chart.Series.Clear(); // Fill data. chart.Series.Add("AW Series 1", new string[] { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" }, new double[] { 1.2, 0.3, 2.1, 2.9, 4.2 }); chart.AxisX.TickLabelSpacing = 2; dataDir = dataDir + @"SetIntervalUnitBetweenLabelsOnAxis_out.docx"; doc.Save(dataDir);
如何隱藏圖表軸
如果要顯示或隱藏圖表軸,只需設置ChartAxis.Hidden屬性的值即可實現。下面的代碼示例顯示如何隱藏圖表的Y軸。
Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Insert chart. Shape shape = builder.InsertChart(ChartType.Column, 432, 252); Chart chart = shape.Chart; // Clear demo data. chart.Series.Clear(); // Fill data. chart.Series.Add("AW Series 1", new string[] { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" }, new double[] { 1.2, 0.3, 2.1, 2.9, 4.2 }); // Hide the Y axis. chart.AxisY.Hidden = true; dataDir = dataDir + @"HideChartAxis_out.docx"; doc.Save(dataDir);
如何對齊圖表標簽
如果要為多行標簽設置文本對齊方式,只需設置ChartAxis.TickLabelAlignment屬性的值即可實現。下面的代碼示例演示如何對標簽對齊進行打勾。
Document doc = new Document(dataDir + "Document.docx"); Shape shape = (Shape)doc.GetChild(NodeType.Shape, 0, true); ChartAxis axis = shape.Chart.AxisX; //This property has effect only for multi-line labels. axis.TickLabelAlignment = ParagraphAlignment.Right; doc.Save(dataDir + "Document_out.docx");
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn