ChartExamples.cs 2.9 KB

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