当前位置:   article > 正文

C#开发用Spire.Presentation增强软件中PPT图表功能

spire.presentation

Spire.Presentation是国产的一个Office接口类库管PPT这一块功能的,支持创建“箱形图”图表,“漏斗图”图表,“直方图”图表,“排列图”图表,“旭日图”图表,“树状图”图表以及“瀑布图”图表等等。类库下载点这里

Spire.Presentation

支持创建“箱形图”图表

  1. Presentation ppt = new Presentation();
  2. IChart chart = ppt.Slides[0].Shapes.AppendChart(ChartType.BoxAndWhisker, new RectangleF(50, 50, 500, 400), false);
  3. string[] seriesLabel = { "Series 1", "Series 2", "Series 3" };
  4. for (int i = 0; i < seriesLabel.Length; i++)
  5. {
  6. chart.ChartData[0, i + 1].Text = "Series 1";
  7. }
  8. string[] categories = {"Category 1", "Category 1", "Category 1", "Category 1", "Category 1", "Category 1", "Category 1",
  9. "Category 2", "Category 2", "Category 2", "Category 2", "Category 2", "Category 2",
  10. "Category 3", "Category 3", "Category 3", "Category 3", "Category 3"};
  11. for (int i = 0; i < categories.Length; i++)
  12. {
  13. chart.ChartData[i + 1, 0].Text = categories[i];
  14. }
  15. double[,] values = new double[18, 3]{{-7,-3,-24},{-10,1,11},{-28,-6,34},{47,2,-21},{35,17,22},{-22,15,19},{17,-11,25},
  16. {-30,18,25},{49,22,56},{37,22,15},{-55,25,31},{14,18,22},{18,-22,36},{-45,25,-17},
  17. {-33,18,22},{18,2,-23},{-33,-22,10},{10,19,22}};
  18. for (int i = 0; i < seriesLabel.Length; i++)
  19. {
  20. for (int j = 0; j < categories.Length; j++)
  21. {
  22. chart.ChartData[j + 1, i + 1].NumberValue = values[j, i];
  23. }
  24. }
  25. chart.Series.SeriesLabel = chart.ChartData[0, 1, 0, seriesLabel.Length];
  26. chart.Categories.CategoryLabels = chart.ChartData[1, 0, categories.Length, 0];
  27. chart.Series[0].Values = chart.ChartData[1, 1, categories.Length, 1];
  28. chart.Series[1].Values = chart.ChartData[1, 2, categories.Length, 2];
  29. chart.Series[2].Values = chart.ChartData[1, 3, categories.Length, 3];
  30. chart.Series[0].ShowInnerPoints = false;
  31. chart.Series[0].ShowOutlierPoints = true;
  32. chart.Series[0].ShowMeanMarkers = true;
  33. chart.Series[0].ShowMeanLine = true;
  34. chart.Series[0].QuartileCalculationType = QuartileCalculation.ExclusiveMedian;
  35. chart.Series[1].ShowInnerPoints = false;
  36. chart.Series[1].ShowOutlierPoints = true;
  37. chart.Series[1].ShowMeanMarkers = true;
  38. chart.Series[1].ShowMeanLine = true;
  39. chart.Series[1].QuartileCalculationType = QuartileCalculation.InclusiveMedian;
  40. chart.Series[2].ShowInnerPoints = false;
  41. chart.Series[2].ShowOutlierPoints = true;
  42. chart.Series[2].ShowMeanMarkers = true;
  43. chart.Series[2].ShowMeanLine = true;
  44. chart.Series[2].QuartileCalculationType = QuartileCalculation.ExclusiveMedian;
  45. chart.HasLegend = true;
  46. chart.ChartTitle.TextProperties.Text = "BoxAndWhisker";
  47. chart.ChartLegend.Position = ChartLegendPositionType.Top;
  48. ppt.SaveToFile(outputFile, FileFormat.Pptx2013);
  49. ppt.Dispose();

支持创建“漏斗图”图表

  1. Presentation ppt = new Presentation();
  2. IChart chart = ppt.Slides[0].Shapes.AppendChart(ChartType.Funnel, new RectangleF(50, 50, 550, 400), false);
  3. chart.ChartData[0, 1].Text = "Series 1";
  4. string[] categories = { "Website Visits ", "Download", "Uploads", "Requested price", "Invoice sent", "Finalized" };
  5. for (int i = 0; i < categories.Length; i++)
  6. {
  7. chart.ChartData[i + 1, 0].Text = categories[i];
  8. }
  9. double[] values = { 50000, 47000, 30000, 15000, 9000, 5600 };
  10. for (int i = 0; i < values.Length; i++)
  11. {
  12. chart.ChartData[i + 1, 1].NumberValue = values[i];
  13. }
  14. chart.Series.SeriesLabel = chart.ChartData[0, 1, 0, 1];
  15. chart.Categories.CategoryLabels = chart.ChartData[1, 0, categories.Length, 0];
  16. chart.Series[0].Values = chart.ChartData[1, 1, values.Length, 1];
  17. chart.ChartTitle.TextProperties.Text = "Funnel";
  18. ppt.SaveToFile(outputFile, FileFormat.PPT);
  19. ppt.Dispose();

支持创建“直方图”图表

  1. Presentation ppt = new Presentation();
  2. IChart chart = ppt.Slides[0].Shapes.AppendChart(ChartType.Histogram, new RectangleF(50, 50, 500, 400), false);
  3. chart.ChartData[0, 0].Text = "Series 1";
  4. double[] values = { 1, 1, 1, 3, 3, 3, 3, 5, 5, 5, 8, 8, 8, 9, 9, 9, 12, 12, 13, 13, 17, 17, 17, 19, 19, 19, 25, 25, 25, 25, 25, 25, 25, 25, 29, 29, 29, 29, 32, 32, 33, 33, 35, 35, 41, 41, 44, 45, 49, 49 };
  5. for (int i = 0; i < values.Length; i++)
  6. {
  7. chart.ChartData[i + 1, 1].NumberValue = values[i];
  8. }
  9. chart.Series.SeriesLabel = chart.ChartData[0, 0, 0, 0];
  10. chart.Series[0].Values = chart.ChartData[1, 0, values.Length, 0];
  11. chart.PrimaryCategoryAxis.NumberOfBins = 7;
  12. chart.PrimaryCategoryAxis.GapWidth = 20;
  13. chart.ChartTitle.TextProperties.Text = "Histogram";
  14. chart.ChartLegend.Position = ChartLegendPositionType.Bottom;
  15. ppt.SaveToFile(outputFile, FileFormat.PPT);

支持创建“排列图”图表

  1. Presentation ppt = new Presentation();
  2. IChart chart = ppt.Slides[0].Shapes.AppendChart(ChartType.Pareto, new RectangleF(50, 50, 500, 400), false);
  3. chart.ChartData[0, 1].Text = "Series 1";
  4. string[] categories = { "Category 1", "Category 2", "Category 4", "Category 3", "Category 4", "Category 2", "Category 1",
  5. "Category 1", "Category 3", "Category 2", "Category 4", "Category 2", "Category 3",
  6. "Category 1", "Category 3", "Category 2", "Category 4", "Category 1", "Category 1",
  7. "Category 3", "Category 2", "Category 4", "Category 1", "Category 1", "Category 3",
  8. "Category 2", "Category 4", "Category 1"};
  9. for (int i = 0; i < categories.Length; i++)
  10. {
  11. chart.ChartData[i + 1, 0].Text = categories[i];
  12. }
  13. double[] values = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
  14. for (int i = 0; i < values.Length; i++)
  15. {
  16. chart.ChartData[i + 1, 1].NumberValue = values[i];
  17. }
  18. chart.Series.SeriesLabel = chart.ChartData[0, 1, 0, 1];
  19. chart.Categories.CategoryLabels = chart.ChartData[1, 0, categories.Length, 0];
  20. chart.Series[0].Values = chart.ChartData[1, 1, values.Length, 1];
  21. chart.PrimaryCategoryAxis.IsBinningByCategory = true;
  22. chart.Series[1].Line.FillFormat.FillType = FillFormatType.Solid;
  23. chart.Series[1].Line.FillFormat.SolidFillColor.Color = Color.Red;
  24. chart.ChartTitle.TextProperties.Text = "Pareto";
  25. chart.HasLegend = true;
  26. chart.ChartLegend.Position = ChartLegendPositionType.Bottom;
  27. ppt.SaveToFile(outputFile, FileFormat.PPT);
  28. ppt.Dispose();

支持创建“旭日图”图表

  1. Presentation ppt = new Presentation();
  2. IChart chart = ppt.Slides[0].Shapes.AppendChart(ChartType.SunBurst, new RectangleF(50, 50, 500, 400), false);
  3. chart.ChartData[0, 3].Text = "Series 1";
  4. string[,] categories = {{"Branch 1","Stem 1","Leaf 1"},{"Branch 1","Stem 1","Leaf 2"},{"Branch 1","Stem 1", "Leaf 3"},
  5. {"Branch 1","Stem 2","Leaf 4"},{"Branch 1","Stem 2","Leaf 5"},{"Branch 1","Leaf 6",null},{"Branch 1","Leaf 7", null},
  6. {"Branch 2","Stem 3","Leaf 8"},{"Branch 2","Leaf 9",null},{"Branch 2","Stem 4","Leaf 10"},{"Branch 2","Stem 4","Leaf 11"},
  7. {"Branch 2","Stem 5","Leaf 12"},{"Branch 3","Stem 5","Leaf 13"},{"Branch 3","Stem 6","Leaf 14"},{"Branch 3","Leaf 15",null}};
  8. for (int i = 0; i < 15; i++)
  9. {
  10. for (int j = 0; j < 3; j++)
  11. chart.ChartData[i + 1, j].Value = categories[i, j];
  12. }
  13. double[] values = { 17, 23, 48, 22, 76, 54, 77, 26, 44, 63, 10, 15, 48, 15, 51 };
  14. for (int i = 0; i < values.Length; i++)
  15. {
  16. chart.ChartData[i + 1, 3].NumberValue = values[i];
  17. }
  18. chart.Series.SeriesLabel = chart.ChartData[0, 3, 0, 3];
  19. chart.Categories.CategoryLabels = chart.ChartData[1, 0, values.Length, 2];
  20. chart.Series[0].Values = chart.ChartData[1, 3, values.Length, 3];
  21. chart.Series[0].DataLabels.CategoryNameVisible = true;
  22. chart.ChartTitle.TextProperties.Text = "SunBurst";
  23. chart.HasLegend = true;
  24. chart.ChartLegend.Position = ChartLegendPositionType.Top;
  25. ppt.SaveToFile(outputFile, FileFormat.PPT);
  26. ppt.Dispose();

支持创建“树状图”图表

  1. Presentation ppt = new Presentation();
  2. IChart chart = ppt.Slides[0].Shapes.AppendChart(ChartType.TreeMap, new RectangleF(50, 50, 500, 400), false);
  3. chart.ChartData[0, 3].Text = "Series 1";
  4. string[,] categories = {{"Branch 1","Stem 1","Leaf 1"},{"Branch 1","Stem 1","Leaf 2"},{"Branch 1","Stem 1", "Leaf 3"},
  5. {"Branch 1","Stem 2","Leaf 4"},{"Branch 1","Stem 2","Leaf 5"},{"Branch 1","Stem 2","Leaf 6"},{"Branch 1","Stem 2","Leaf 7"},
  6. {"Branch 2","Stem 3","Leaf 8"},{"Branch 2","Stem 3","Leaf 9"},{"Branch 2","Stem 4","Leaf 10"},{"Branch 2","Stem 4","Leaf 11"},
  7. {"Branch 2","Stem 5","Leaf 12"},{"Branch 3","Stem 5","Leaf 13"},{"Branch 3","Stem 6","Leaf 14"},{"Branch 3","Stem 6","Leaf 15"}};
  8. for (int i = 0; i < 15; i++)
  9. {
  10. for (int j = 0; j < 3; j++)
  11. chart.ChartData[i + 1, j].Text = categories[i, j];
  12. }
  13. double[] values = { 17, 23, 48, 22, 76, 54, 77, 26, 44, 63, 10, 15, 48, 15, 51 };
  14. for (int i = 0; i < values.Length; i++)
  15. {
  16. chart.ChartData[i + 1, 3].NumberValue = values[i];
  17. }
  18. chart.Series.SeriesLabel = chart.ChartData[0, 3, 0, 3];
  19. chart.Categories.CategoryLabels = chart.ChartData[1, 0, values.Length, 2];
  20. chart.Series[0].Values = chart.ChartData[1, 3, values.Length, 3];
  21. chart.Series[0].DataLabels.CategoryNameVisible = true;
  22. chart.Series[0].TreeMapLabelOption = TreeMapLabelOption.Banner;
  23. chart.ChartTitle.TextProperties.Text = "TreeMap";
  24. chart.HasLegend = true;
  25. chart.ChartLegend.Position = ChartLegendPositionType.Top;
  26. ppt.SaveToFile(outputFile, FileFormat.PPT);

支持创建“瀑布图”图表

  1. Presentation ppt = new Presentation();
  2. IChart chart = ppt.Slides[0].Shapes.AppendChart(ChartType.WaterFall, new RectangleF(50, 50, 500, 400), false);
  3. chart.ChartData[0, 1].Text = "Series 1";
  4. string[] categories = { "Category 1", "Category 2", "Category 3", "Category 4", "Category 5", "Category 6", "Category 7" };
  5. for (int i = 0; i < categories.Length; i++)
  6. {
  7. chart.ChartData[i + 1, 0].Text = categories[i];
  8. }
  9. double[] values = { 100, 20, 50, -40, 130, -60, 70 };
  10. for (int i = 0; i < values.Length; i++)
  11. {
  12. chart.ChartData[i + 1, 1].NumberValue = values[i];
  13. }
  14. chart.Series.SeriesLabel = chart.ChartData[0, 1, 0, 1];
  15. chart.Categories.CategoryLabels = chart.ChartData[1, 0, categories.Length, 0];
  16. chart.Series[0].Values = chart.ChartData[1, 1, values.Length, 1];
  17. ChartDataPoint chartDataPoint = new ChartDataPoint(chart.Series[0]);
  18. chartDataPoint.Index = 2;
  19. chartDataPoint.SetAsTotal = true;
  20. chart.Series[0].DataPoints.Add(chartDataPoint);
  21. ChartDataPoint chartDataPoint2 = new ChartDataPoint(chart.Series[0]);
  22. chartDataPoint2.Index = 5;
  23. chartDataPoint2.SetAsTotal = true;
  24. chart.Series[0].DataPoints.Add(chartDataPoint2);
  25. chart.Series[0].ShowConnectorLines = true;
  26. chart.Series[0].DataLabels.LabelValueVisible = true;
  27. chart.ChartLegend.Position = ChartLegendPositionType.Right;
  28. chart.ChartTitle.TextProperties.Text = "WaterFall";
  29. ppt.SaveToFile(outputFile, FileFormat.PPT);
  30. ppt.Dispose();
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/728392
推荐阅读
  

闽ICP备14008679号