public Bitmap GetChart()
        {
            var chart = new BarChart(Entries)
            {
                Title         = "Grafikon usporedbe s prethodnom godinom",
                LegendTitleI  = LegendI,
                LegendTitleII = LegendII
            };

            return(chart.Draw());
        }
Beispiel #2
0
        public void TestBarChart()
        {
            var entries = new[]
            {
                new Entry(200)
                {
                    Label      = "January",
                    ValueLabel = "200",
                    Color      = SKColor.Parse("#266489")
                },
                new Entry(400)
                {
                    Label      = "February",
                    ValueLabel = "400",
                    Color      = SKColor.Parse("#68B9C0")
                },
                new Entry(600)
                {
                    Label      = "March",
                    ValueLabel = "600",
                    Color      = SKColor.Parse("#90D585")
                }
            };

            var chart = new BarChart();

            chart.Entries         = entries;
            chart.ValueLabelStyle = ValueLabelSyle.VerticalDisplay;

            var dir = Path.Combine(AppContext.BaseDirectory, "Data");

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            var width  = 500;
            var height = 300;

            using (var bitmap = new SKBitmap(width, height))
                using (var canvas = new SKCanvas(bitmap))
                {
                    chart.Draw(canvas, width, height);
                    var pngImage = SKImage.FromBitmap(bitmap).Encode(SKEncodedImageFormat.Png, 100);

                    using (var fs = File.Create(Path.Combine(dir, Guid.NewGuid().ToString() + ".png")))
                    {
                        pngImage.SaveTo(fs);
                        fs.Flush();
                        fs.Close();
                    }
                }
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            Random            random  = new Random();
            List <TestResult> results = new List <TestResult>();

            for (int i = 0; i < 21; i++)
            {
                double r = random.NextDouble() * 6 - 3;
                results.Add(new TestResult()
                {
                    RelatedTest = new Test()
                    {
                        Name = "LD" + i.ToString()
                    },
                    ZScore     = (int)(random.NextDouble() * 6 - 3),
                    Percentile = (int)(random.NextDouble() * 100)
                });
            }

            List <TestResultGroup> resultGroups = new List <TestResultGroup>(new TestResultGroup[] {
                new TestResultGroup()
                {
                    TestGroupInfo = new TestGroup()
                    {
                        Name = "Symptom Checklist - 90 - Revised"
                    },
                    Tests = results
                }
            });

            Patient johnDoe = new Patient()
            {
                Name                = "John Doe",
                PreferredName       = "Johnny",
                DateOfBirth         = new DateTime(628243894905389400),
                DateOfTesting       = new DateTime(628243894905389400),
                MedicalRecordNumber = 123456,
                ResultGroups        = resultGroups
            };

            Patient patient = johnDoe;

            Console.WriteLine(patient.DateOfBirth);


            string templatePath = @"Reports\ReportTemplate\Report_Template.dotx";
            string newfilePath  = @"Reports\GeneratedReports\" + patient.Name + ".docx";
            string vizPath      = @"Reports\GeneratedReports\Visualization.docx";
            string imagePath    = @"Reports\GeneratedReports\renderedVisualization2.png";

            if (File.Exists(newfilePath))
            {
                File.Delete(newfilePath);
            }

            File.Copy(templatePath, newfilePath);

            var entries = new List <Entry>();

            int[]  green  = new int[] { 0, 255, 0 };
            int[]  yellow = new int[] { 255, 255, 0 };
            int[]  red    = new int[] { 255, 0, 0 };
            double interp;
            string hexcol;
            int    percentile;

            using (WordprocessingDocument myDoc = WordprocessingDocument.Open(newfilePath, true)){
                myDoc.ChangeDocumentType(DocumentFormat.OpenXml.WordprocessingDocumentType.Document);
                var wordAPI = new WordAPI(myDoc);
                wordAPI.InsertPatientData(patient);
                foreach (TestResultGroup testResultGroup in patient.ResultGroups)
                {
                    wordAPI.DisplayTestGroup(testResultGroup);

                    foreach (TestResult result in testResultGroup.Tests)
                    {
                        interp = 2 * Math.Abs(0.01 * (double)result.Percentile - 0.5);
                        if (interp < 0.5)
                        {
                            hexcol = ColToHex(ColorInterpolation(green, yellow, 2 * interp));
                        }
                        else
                        {
                            hexcol = ColToHex(ColorInterpolation(yellow, red, 2 * (interp - 0.5)));
                        }
                        if (result.Percentile == 0)
                        {
                            percentile = 1;
                        }
                        else
                        {
                            percentile = result.Percentile;
                        }
                        entries.Add(new Entry(percentile)
                        {
                            Label      = result.RelatedTest.Name,
                            ValueLabel = result.Percentile.ToString(),
                            Color      = SKColor.Parse(hexcol)
                        });
                    }
                }
                wordAPI.PageBreak();
                //InsertPicturePng(myDoc, imagePath,7,1.2);
                //JoinFile(myDoc,vizPath);
            }

            var chart = new BarChart()
            {
                Entries          = entries,
                MaxValue         = 100,
                MinValue         = 0,
                LabelOrientation = Microcharts.Orientation.Vertical
            };

            int width  = 800;
            int height = 300;

            SKImageInfo info    = new SKImageInfo(width, height);
            SKSurface   surface = SKSurface.Create(info);

            SKCanvas canvas = surface.Canvas;

            chart.Draw(canvas, width, height);

            // create an image and then get the PNG (or any other) encoded data
            using (var data = surface.Snapshot().Encode(SKEncodedImageFormat.Png, 80)) {
                // save the data to a stream
                using (var stream = File.OpenWrite("one.png")) {
                    data.SaveTo(stream);
                }
            }

            using (WordprocessingDocument myDoc = WordprocessingDocument.Open(newfilePath, true)){
                var wordAPI = new WordAPI(myDoc);
                wordAPI.InsertPicturePng("one.png", 6, 3);
            }

            //Console.WriteLine("Modified");
        }
Beispiel #4
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            BarChart barChart     = new BarChart(500, 500, 5);
            var      barChartData = new BarChartData()
            {
                Bars = new[] {
                    new BarData()
                    {
                        BarNum   = 0,
                        Name     = "МДТ6",
                        Sections = new[]
                        {
                            new BarSectionData()
                            {
                                Name = "Прошло труб", SectionNum = 0, Value = 10
                            },
                            new BarSectionData()
                            {
                                Name = "Повторы", SectionNum = 1, Value = 20
                            },
                            new BarSectionData()
                            {
                                Name = "Образцы", SectionNum = 2, Value = 5
                            },
                        },
                        CaptionText = "10/35"
                    },
                    new BarData()
                    {
                        BarNum   = 1,
                        Name     = "Сканер",
                        Sections = new[]
                        {
                            new BarSectionData()
                            {
                                Name = "Прошло труб", SectionNum = 0, Value = 10
                            },
                            new BarSectionData()
                            {
                                Name = "Повторы", SectionNum = 1, Value = 3
                            },
                            new BarSectionData()
                            {
                                Name = "Образцы", SectionNum = 2, Value = 8
                            },
                        },
                        CaptionText = "10/22"
                    },
                }
            };

            barChart.SetData(barChartData);
            using (MemoryStream ms = new MemoryStream())
            {
                barChart.Draw().Save(ms, ImageFormat.Bmp);
                var bitmapImage = new BitmapImage();
                ms.Seek(0, SeekOrigin.Begin);
                bitmapImage.BeginInit();
                bitmapImage.CacheOption  = BitmapCacheOption.OnLoad;
                bitmapImage.StreamSource = ms;
                bitmapImage.EndInit();
                image1.Source = bitmapImage;
            }
        }
Beispiel #5
0
        public static Stream MakePatientPercentileChart(TestResultGroup testResultGroup)
        {
            var entries = new List <Entry>();

            int[]  green  = new int[] { 0, 255, 0 };
            int[]  yellow = new int[] { 255, 255, 0 };
            int[]  red    = new int[] { 255, 0, 0 };
            double interp;
            string hexcol;
            int    percentile;

            foreach (TestResult result in testResultGroup.Tests)
            {
                interp = 0.01 * result.Percentile;
                if (interp < 0.5)
                {
                    hexcol = ColToHex(LinearInterpolation(red, yellow, 2 * interp));
                }
                else
                {
                    hexcol = ColToHex(LinearInterpolation(yellow, green, 2 * (interp - 0.5)));
                }
                if (Math.Abs(result.Percentile) < 1)
                {
                    percentile = 1;
                }
                else
                {
                    percentile = (int)result.Percentile;
                }
                entries.Add(new Entry(percentile)
                {
                    Label      = result.Test.Name,
                    ValueLabel = result.Percentile.ToString(),
                    Color      = SKColor.Parse(hexcol)
                });
            }

            var chart = new BarChart()
            {
                Entries          = entries,
                MaxValue         = 100,
                MinValue         = 0,
                LabelOrientation = Microcharts.Orientation.Vertical
            };

            int width  = entries.Count * 50;
            int height = 600;

            SKImageInfo info    = new SKImageInfo(width, height);
            SKSurface   surface = SKSurface.Create(info);

            SKCanvas canvas = surface.Canvas;

            chart.Draw(canvas, width, height);

            Stream imageStream = new MemoryStream();

            // create an image and then get the PNG (or any other) encoded data
            using (var data = surface.Snapshot().Encode(SKEncodedImageFormat.Png, 80)) {
                // save the data to a stream
                data.SaveTo(imageStream);
            }

            imageStream = RotateImage(imageStream);

            return(imageStream);
        }