Files
QuestPDF/QuestPDF.Examples/ChartExamples.cs
T

85 lines
2.8 KiB
C#
Raw Normal View History

2021-11-30 00:34:04 +01:00
using System.Linq;
2021-11-09 10:26:46 -07:00
using NUnit.Framework;
using QuestPDF.Examples.Engine;
using QuestPDF.Fluent;
using QuestPDF.Helpers;
using QuestPDF.Infrastructure;
using Microcharts;
using SkiaSharp;
namespace QuestPDF.Examples
{
public class ChartExample
{
[Test]
public void MicrochartChart()
{
var entries = new[]
{
new ChartEntry(212)
{
Label = "UWP",
ValueLabel = "112",
Color = SKColor.Parse("#2c3e50")
},
new ChartEntry(248)
{
Label = "Android",
ValueLabel = "648",
Color = SKColor.Parse("#77d065")
},
new ChartEntry(128)
{
Label = "iOS",
ValueLabel = "428",
Color = SKColor.Parse("#b455b6")
},
new ChartEntry(514)
{
Label = "Forms",
ValueLabel = "214",
Color = SKColor.Parse("#3498db")
}
};
RenderingTest
.Create()
2021-11-30 00:34:04 +01:00
.PageSize(400, 600)
.ProduceImages()
2021-11-09 10:26:46 -07:00
.ShowResults()
.Render(container =>
{
2021-11-30 00:34:04 +01:00
container
.Background(Colors.White)
.Padding(25)
.Stack(stack =>
2021-11-09 10:26:46 -07:00
{
2021-11-30 00:34:04 +01:00
stack
.Item()
.PaddingBottom(10)
.Text("Chart example", TextStyle.Default.Size(20).SemiBold().Color(Colors.Blue.Medium));
stack
.Item()
.Border(1)
.ExtendHorizontal()
.Height(300)
.Canvas((canvas, size) =>
{
var chart = new BarChart
{
Entries = entries,
LabelOrientation = Orientation.Horizontal,
ValueLabelOrientation = Orientation.Horizontal,
IsAnimated = false,
};
chart.DrawContent(canvas, (int)size.Width, (int)size.Height);
});
});
2021-11-09 10:26:46 -07:00
});
}
}
}