ChartExamples.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using System.Linq;
  2. using NUnit.Framework;
  3. using QuestPDF.Examples.Engine;
  4. using QuestPDF.Fluent;
  5. using QuestPDF.Helpers;
  6. using QuestPDF.Infrastructure;
  7. using Microcharts;
  8. using SkiaSharp;
  9. namespace QuestPDF.Examples
  10. {
  11. public class ChartExample
  12. {
  13. [Test]
  14. public void MicrochartChart()
  15. {
  16. var entries = new[]
  17. {
  18. new ChartEntry(212)
  19. {
  20. Label = "UWP",
  21. ValueLabel = "112",
  22. Color = SKColor.Parse("#2c3e50")
  23. },
  24. new ChartEntry(248)
  25. {
  26. Label = "Android",
  27. ValueLabel = "648",
  28. Color = SKColor.Parse("#77d065")
  29. },
  30. new ChartEntry(128)
  31. {
  32. Label = "iOS",
  33. ValueLabel = "428",
  34. Color = SKColor.Parse("#b455b6")
  35. },
  36. new ChartEntry(514)
  37. {
  38. Label = "Forms",
  39. ValueLabel = "214",
  40. Color = SKColor.Parse("#3498db")
  41. }
  42. };
  43. RenderingTest
  44. .Create()
  45. .PageSize(400, 600)
  46. .ProduceImages()
  47. .ShowResults()
  48. .Render(container =>
  49. {
  50. container
  51. .Background(Colors.White)
  52. .Padding(25)
  53. .Column(column =>
  54. {
  55. column
  56. .Item()
  57. .PaddingBottom(10)
  58. .Text("Chart example")
  59. .Size(20)
  60. .SemiBold()
  61. .Color(Colors.Blue.Medium);
  62. column
  63. .Item()
  64. .Border(1)
  65. .ExtendHorizontal()
  66. .Height(300)
  67. .Canvas((canvas, size) =>
  68. {
  69. var chart = new BarChart
  70. {
  71. Entries = entries,
  72. LabelOrientation = Orientation.Horizontal,
  73. ValueLabelOrientation = Orientation.Horizontal,
  74. IsAnimated = false,
  75. };
  76. chart.DrawContent(canvas, (int)size.Width, (int)size.Height);
  77. });
  78. });
  79. });
  80. }
  81. }
  82. }