ChartExamples.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using NUnit.Framework;
  2. using QuestPDF.Examples.Engine;
  3. using QuestPDF.Fluent;
  4. using QuestPDF.Helpers;
  5. using QuestPDF.Infrastructure;
  6. using Microcharts;
  7. using SkiaSharp;
  8. namespace QuestPDF.Examples
  9. {
  10. public class ChartExample
  11. {
  12. [Test]
  13. public void MicrochartChart()
  14. {
  15. var entries = new[]
  16. {
  17. new ChartEntry(212)
  18. {
  19. Label = "UWP",
  20. ValueLabel = "112",
  21. Color = SKColor.Parse("#2c3e50")
  22. },
  23. new ChartEntry(248)
  24. {
  25. Label = "Android",
  26. ValueLabel = "648",
  27. Color = SKColor.Parse("#77d065")
  28. },
  29. new ChartEntry(128)
  30. {
  31. Label = "iOS",
  32. ValueLabel = "428",
  33. Color = SKColor.Parse("#b455b6")
  34. },
  35. new ChartEntry(514)
  36. {
  37. Label = "Forms",
  38. ValueLabel = "214",
  39. Color = SKColor.Parse("#3498db")
  40. }
  41. };
  42. RenderingTest
  43. .Create()
  44. .PageSize(300, 300)
  45. .ShowResults()
  46. .Render(container =>
  47. {
  48. container.Extend().Canvas((canvas, size) =>
  49. {
  50. var bar = new BarChart
  51. {
  52. Entries = entries,
  53. IsAnimated = false,
  54. };
  55. bar.Draw(canvas, (int)size.Width, (int)size.Height);
  56. });
  57. });
  58. }
  59. }
  60. }