• 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);

    请查看结果如下:

  • 相关阅读:
    【MATLAB教程案例39】语音信号的PCM编解码matlab仿真学习
    js中indexOf 的按位化简
    记一次http接口自动重试现象的排查
    vim没有clipboard,没法复制到系统剪切板,通过xclip将复制、删除的内容放到系统剪切板
    新手又该如何操作呢?操作时候注意哪些问题?
    力扣每日一题 ---- 2905. 找出满足差值条件的下标 II
    机器学习中的 K-均值聚类算法及其优缺点。
    dubbo项目实战代码展示
    JavaScript · 9:数据类型转换 & 隐式转换
    linux常用的一些辅助命令
  • 原文地址:https://blog.csdn.net/m0_67129275/article/details/125534101