Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Program.cs 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using Xceed.Words.NET;
  8. namespace ConsoleApp1
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. // Creates a document
  15. using (DocX document = DocX.Create(@"R:\6.docx", DocumentTypes.Document))
  16. {
  17. // Add a title
  18. document.InsertParagraph("Bar Chart").FontSize(15d).SpacingAfter(50d).Alignment = Alignment.center;
  19. // Create a bar chart.
  20. var c = new BarChart();
  21. c.AddLegend(ChartLegendPosition.Bottom, false);
  22. c.BarDirection = BarDirection.Column;
  23. c.BarGrouping = BarGrouping.Standard;
  24. c.GapWidth = 200;
  25. // Create the data.
  26. var canada = CreateCanadaExpenses();
  27. var usa = CreateUSAExpenses();
  28. var brazil = CreateBrazilExpenses();
  29. // Create and add series
  30. var s1 = new Series("Brazil");
  31. s1.Color = Color.FromArgb(91, 155, 213);
  32. s1.Bind(brazil, "Category", "Expenses");
  33. s1.ShowValue = true;
  34. c.AddSeries(s1);
  35. var s2 = new Series("USA");
  36. s2.Color = Color.FromArgb(237, 125, 49);
  37. s2.Bind(usa, "Category", "Expenses");
  38. s2.ShowValue = true;
  39. c.AddSeries(s2);
  40. var s3 = new Series("Canada");
  41. s3.Color = Color.Gray;
  42. s3.Bind(canada, "Category", "Expenses");
  43. c.AddSeries(s3);
  44. //set value
  45. c.Title = "贺州供有点";
  46. c.ShowDataTable = true;
  47. // Insert the chart into the document.
  48. document.InsertChart(c);
  49. document.InsertParagraph("贺州供电局").FontSize(15).SpacingAfter(10d);
  50. document.Save();
  51. }
  52. }
  53. public static List<ChartData> CreateCanadaExpenses()
  54. {
  55. var canada = new List<ChartData>();
  56. canada.Add(new ChartData() { Category = "Food", Expenses = 100 });
  57. canada.Add(new ChartData() { Category = "Housing", Expenses = 120 });
  58. canada.Add(new ChartData() { Category = "Transportation", Expenses = 140 });
  59. canada.Add(new ChartData() { Category = "Health Care", Expenses = 150 });
  60. return canada;
  61. }
  62. public static List<ChartData> CreateUSAExpenses()
  63. {
  64. var usa = new List<ChartData>();
  65. usa.Add(new ChartData() { Category = "Food", Expenses = 200 });
  66. usa.Add(new ChartData() { Category = "Housing", Expenses = 150 });
  67. usa.Add(new ChartData() { Category = "Transportation", Expenses = 110 });
  68. usa.Add(new ChartData() { Category = "Health Care", Expenses = 100 });
  69. return usa;
  70. }
  71. public static List<ChartData> CreateBrazilExpenses()
  72. {
  73. var brazil = new List<ChartData>();
  74. brazil.Add(new ChartData() { Category = "Food", Expenses = 125 });
  75. brazil.Add(new ChartData() { Category = "Housing", Expenses = 80 });
  76. brazil.Add(new ChartData() { Category = "Transportation", Expenses = 110 });
  77. brazil.Add(new ChartData() { Category = "Health Care", Expenses = 60 });
  78. return brazil;
  79. }
  80. internal class ChartData
  81. {
  82. public string Category
  83. {
  84. get;
  85. set;
  86. }
  87. public double Expenses
  88. {
  89. get;
  90. set;
  91. }
  92. }
  93. }
  94. }