Aspose.Words for .NET圖表教程——關(guān)于使用圖表數(shù)據(jù)
Aspose.Words For .Net是一種高級Word文檔處理API,用于執(zhí)行各種文檔管理和操作任務(wù)。API支持生成,修改,轉(zhuǎn)換,呈現(xiàn)和打印文檔,而無需在跨平臺應(yīng)用程序中直接使用Microsoft Word。此外,API支持所有流行的Word處理文件格式,并允許將Word文檔導(dǎo)出或轉(zhuǎn)換為固定布局文件格式和最常用的圖像/多媒體格式。
接下來我們將進入關(guān)于“使用圖表”的介紹,在Aspose.Words中學(xué)會關(guān)于ChartSeries類的相關(guān),包括使用單個ChartSeries類、使用ChartSeries的單個圖表數(shù)據(jù)點、使用單個ChartSeries的圖表數(shù)據(jù)標簽。
>>Aspose.Words for .NET更新至最新版v19.12,支持轉(zhuǎn)換為PDF 1.7標準,點擊下載體驗
使用單個ChartSeries類
以下是處理特定系列的方法。
// Get first series. ChartSeries series0 = shape.Chart.Series[0]; // Get second series. ChartSeries series1 = shape.Chart.Series[1]; // Change first series name. series0.Name = "My Name1"; // Change second series name. series1.Name = "My Name2"; // You can also specify whether the line connecting the points on the chart shall be smoothed using Catmull-Rom splines. series0.Smooth = true; series1.Smooth = true;
請查看結(jié)果如下:
所有單個ChartSeries都有默認的ChartDataPoint選項,請嘗試使用以下代碼進行更改:
// Specifies whether by default the parent element shall inverts its colors if the value is negative. series0.InvertIfNegative = true; // Set default marker symbol and size. series0.Marker.Symbol = MarkerSymbol.Circle; series0.Marker.Size = 15; series1.Marker.Symbol = MarkerSymbol.Star; series1.Marker.Size = 10;
還想要更多嗎?您可以點擊閱讀【2019 · Aspose最新資源整合】,查找需要的教程資源。讓人興奮的是Aspose.Total限時直降10000元!java版另送IDE開發(fā)工具一套!聯(lián)系慧都客服立馬1分鐘了解全部咨詢!
如何使用ChartSeries的單個ChartDataPoint
使用ChartDataPoint,可以自定義圖表系列的單個數(shù)據(jù)點的格式。
// The path to the documents directory. string dataDir = RunExamples.GetDataDir_WorkingWithCharts(); Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); Shape shape = builder.InsertChart(ChartType.Line, 432, 252); Chart chart = shape.Chart; // Get first series. ChartSeries series0 = shape.Chart.Series[0]; // Get second series. ChartSeries series1 = shape.Chart.Series[1]; ChartDataPointCollection dataPointCollection = series0.DataPoints; // Add data point to the first and second point of the first series. ChartDataPoint dataPoint00 = dataPointCollection.Add(0); ChartDataPoint dataPoint01 = dataPointCollection.Add(1); // Set explosion. dataPoint00.Explosion = 50; // Set marker symbol and size. dataPoint00.Marker.Symbol = MarkerSymbol.Circle; dataPoint00.Marker.Size = 15; dataPoint01.Marker.Symbol = MarkerSymbol.Diamond; dataPoint01.Marker.Size = 20; // Add data point to the third point of the second series. ChartDataPoint dataPoint12 = series1.DataPoints.Add(2); dataPoint12.InvertIfNegative = true; dataPoint12.Marker.Symbol = MarkerSymbol.Star; dataPoint12.Marker.Size = 20; dataDir = dataDir + @"SingleChartDataPoint_out.docx"; doc.Save(dataDir);
請查看結(jié)果如下:
如何使用單個ChartSeries的ChartDataLabel
使用ChartDataLabel,您可以指定圖表系列的單個數(shù)據(jù)標簽的格式,例如顯示/隱藏LegendKey,CategoryName,SeriesName,Value等。
Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); Shape shape = builder.InsertChart(ChartType.Bar, 432, 252); Chart chart = shape.Chart; // Get first series. ChartSeries series0 = shape.Chart.Series[0]; ChartDataLabelCollection dataLabelCollection = series0.DataLabels; // Add data label to the first and second point of the first series. ChartDataLabel chartDataLabel00 = dataLabelCollection.Add(0); ChartDataLabel chartDataLabel01 = dataLabelCollection.Add(1); // Set properties. chartDataLabel00.ShowLegendKey = true; // By default, when you add data labels to the data points in a pie chart, leader lines are displayed for data labels that are // Positioned far outside the end of data points. Leader lines create a visual connection between a data label and its // Corresponding data point. chartDataLabel00.ShowLeaderLines = true; chartDataLabel00.ShowCategoryName = false; chartDataLabel00.ShowPercentage = false; chartDataLabel00.ShowSeriesName = true; chartDataLabel00.ShowValue = true; chartDataLabel00.Separator = "/"; chartDataLabel01.ShowValue = true; dataDir = dataDir + @"SimpleBarChart_out.docx"; doc.Save(dataDir);
請查看結(jié)果如下: