• Aspose.Words for .NET图表教程——关于使用图表数据


    Aspose.Words For .Net是一种高级Word文档处理API,用于执行各种文档管理和操作任务。API支持生成,修改,转换,呈现和打印文档,而无需在跨平台应用程序中直接使用Microsoft Word。此外,API支持所有流行的Word处理文件格式,并允许将Word文档导出或转换为固定布局文件格式和最常用的图像/多媒体格式。

    接下来我们将进入关于“使用图表”的介绍,在Aspose.Words中学会关于ChartSeries类的相关,包括使用单个ChartSeries类、使用ChartSeries的单个图表数据点、使用单个ChartSeries的图表数据标签。

    >>Aspose.Words for .NET更新至最新版,支持转换为PDF 1.7标准,点击下载体验

    欢迎下载|体验更多Aspose文档管理产品或 加入Aspose技术交流群(761297826)


    使用单个ChartSeries类

    以下是处理特定系列的方法。

    1. // Get first series.
    2. ChartSeries series0 = shape.Chart.Series[0];
    3. // Get second series.
    4. ChartSeries series1 = shape.Chart.Series[1];
    5. // Change first series name.
    6. series0.Name = "My Name1";
    7. // Change second series name.
    8. series1.Name = "My Name2";
    9. // You can also specify whether the line connecting the points on the chart shall be smoothed using Catmull-Rom splines.
    10. series0.Smooth = true;
    11. series1.Smooth = true;

    请查看结果如下:

    所有单个ChartSeries都有默认的ChartDataPoint选项,请尝试使用以下代码进行更改:

    1. // Specifies whether by default the parent element shall inverts its colors if the value is negative.
    2. series0.InvertIfNegative = true;
    3. // Set default marker symbol and size.
    4. series0.Marker.Symbol = MarkerSymbol.Circle;
    5. series0.Marker.Size = 15;
    6. series1.Marker.Symbol = MarkerSymbol.Star;
    7. series1.Marker.Size = 10;

    如何使用ChartSeries的单个ChartDataPoint

    使用ChartDataPoint,可以自定义图表系列的单个数据点的格式。

    1. // The path to the documents directory.
    2. string dataDir = RunExamples.GetDataDir_WorkingWithCharts();
    3. Document doc = new Document();
    4. DocumentBuilder builder = new DocumentBuilder(doc);
    5. Shape shape = builder.InsertChart(ChartType.Line, 432252);
    6. Chart chart = shape.Chart;
    7. // Get first series.
    8. ChartSeries series0 = shape.Chart.Series[0];
    9. // Get second series.
    10. ChartSeries series1 = shape.Chart.Series[1];
    11. ChartDataPointCollection dataPointCollection = series0.DataPoints;
    12. // Add data point to the first and second point of the first series.
    13. ChartDataPoint dataPoint00 = dataPointCollection.Add(0);
    14. ChartDataPoint dataPoint01 = dataPointCollection.Add(1);
    15. // Set explosion.
    16. dataPoint00.Explosion = 50;
    17. // Set marker symbol and size.
    18. dataPoint00.Marker.Symbol = MarkerSymbol.Circle;
    19. dataPoint00.Marker.Size = 15;
    20. dataPoint01.Marker.Symbol = MarkerSymbol.Diamond;
    21. dataPoint01.Marker.Size = 20;
    22. // Add data point to the third point of the second series.
    23. ChartDataPoint dataPoint12 = series1.DataPoints.Add(2);
    24. dataPoint12.InvertIfNegative = true;
    25. dataPoint12.Marker.Symbol = MarkerSymbol.Star;
    26. dataPoint12.Marker.Size = 20;
    27. dataDir = dataDir + @"SingleChartDataPoint_out.docx";
    28. doc.Save(dataDir);

    请查看结果如下:

    如何使用单个ChartSeries的ChartDataLabel

    使用ChartDataLabel,您可以指定图表系列的单个数据标签的格式,例如显示/隐藏LegendKey,CategoryName,SeriesName,Value等。

    1. Document doc = new Document();
    2. DocumentBuilder builder = new DocumentBuilder(doc);
    3. Shape shape = builder.InsertChart(ChartType.Bar, 432252);
    4. Chart chart = shape.Chart;
    5. // Get first series.
    6. ChartSeries series0 = shape.Chart.Series[0];
    7. ChartDataLabelCollection dataLabelCollection = series0.DataLabels;
    8. // Add data label to the first and second point of the first series.
    9. ChartDataLabel chartDataLabel00 = dataLabelCollection.Add(0);
    10. ChartDataLabel chartDataLabel01 = dataLabelCollection.Add(1);
    11. // Set properties.
    12. chartDataLabel00.ShowLegendKey = true;
    13. // By defaultwhen you add data labels to the data points in a pie chart, leader lines are displayed for data labels that are
    14. // Positioned far outside the end of data points. Leader lines create a visual connection between a data label and its 
    15. // Corresponding data point.
    16. chartDataLabel00.ShowLeaderLines = true;
    17. chartDataLabel00.ShowCategoryName = false;
    18. chartDataLabel00.ShowPercentage = false;
    19. chartDataLabel00.ShowSeriesName = true;
    20. chartDataLabel00.ShowValue = true;
    21. chartDataLabel00.Separator = "/";
    22. chartDataLabel01.ShowValue = true;
    23. dataDir = dataDir + @"SimpleBarChart_out.docx";
    24. doc.Save(dataDir);

    请查看结果如下:

  • 相关阅读:
    YOLOv8轻量化模型:模型轻量化设计 | 轻量级可重参化EfficientRepBiPAN | 来自YOLOv6思想
    基于强化学习的机组组合问题求解方法研究
    ES 2023新特性速解
    为了方便问题的快速定位,如您在使用
    【Push Kit】推送返回80100016错误
    MySQL数据库基本操作+用户管理+用户授权
    敏捷项目管理解锁:2023年使用YouTrack的全面指南
    重生之我要学后端01--后端语言选择和对应框架选择
    【附源码】Python计算机毕业设计天润律师事务所管理系统
    基于Vue3水印组件封装:防篡改守护!
  • 原文地址:https://blog.csdn.net/m0_67129275/article/details/125534101