Ejemplo n.º 1
0
 protected DrawingElement CreatePieChart(
     string title,
     string units,
     Tuple <string, float>[] pieChartData,
     TotalHandling totalHandling,
     string css)
 {
     return(new PieChartDrawing(150, title, units, pieChartData, totalHandling, "n1", css));
 }
Ejemplo n.º 2
0
        public PieChartDrawing(
            float width,
            string title,
            string units,
            Tuple <string, float>[] data,
            TotalHandling totalHandling,
            string numberFormat = "n1",
            string css          = "piechart")
        {
            CssClass = css;

            LeftMargin   = width / 10f;
            RightMargin  = width / 10f;
            TopMargin    = width / 20f;
            BottomMargin = width / 20f;

            AddChild(new TextDrawing
            {
                Text = new[] { title }
            }
                     .HeadingLevel(2));

            var pie = new PieDrawing(width, data, css);

            var total = 0f;

            switch (totalHandling)
            {
            case TotalHandling.Sum:
                total = data.Aggregate(0f, (s, v) => s + v.Item2);
                break;

            case TotalHandling.Average:
                total = data.Aggregate(0f, (s, v) => s + v.Item2) / data.Length;
                break;

            case TotalHandling.Minimum:
                total = data.Min(v => v.Item2);
                break;

            case TotalHandling.Maximum:
                total = data.Max(v => v.Item2);
                break;
            }

            pie.AddChild(new TextDrawing
            {
                TextSize = 2f,
                Text     = new[] { total.ToString(numberFormat), units }
            });

            AddChild(pie);

            AddChild(new LegendDrawing(units, numberFormat, data, css));
        }