Ejemplo n.º 1
0
        public void ApexChartTest_Json()
        {
            var chart = new ApexChart(ChartName, Selector, null, formatJson: false);
            var json  = chart.ToString();

            Assert.False(string.IsNullOrWhiteSpace(json));
        }
Ejemplo n.º 2
0
        public void ApexChartTest_NullOptions()
        {
            var chart       = new ApexChart(ChartName, Selector, null, formatJson: false);
            var chartJson   = chart.ToString();
            var options     = "null";
            var chartSample = $"var {ChartName} = new ApexCharts(document.querySelector(\"{Selector}\"), {options});" + Environment.NewLine +
                              $"{ChartName}.render();";

            Assert.Equal(chartSample, chartJson);
        }
Ejemplo n.º 3
0
        public void ApexChartTest_EmptyChart()
        {
            var options = new ChartOptions();

            var chart             = new ApexChart(ChartName, Selector, options, formatJson: false);
            var chartJson         = chart.ToString();
            var jsonOptionsSample = "{\"chart\":{\"id\":\"" + ChartName + "\"}}";
            var chartSample       = $"var {ChartName} = new ApexCharts(document.querySelector(\"{Selector}\"), {jsonOptionsSample});" + Environment.NewLine +
                                    $"{ChartName}.render();";

            Assert.Equal(chartSample, chartJson);
        }
        public void Test1()
        {
            var json = new ApexChart().AreaChart()
                       .AddData("", new[] { 1, 2, 3 })
                       .SetLabels(new [] { "Player 7", "Player 10", "Player 9" })
                       .SetTitle("Top 3 scorers of the team.")
                       .SetSubTitle("Season 2021.")
                       .ToJson();

            Console.WriteLine(json);
            Assert.Pass();
        }
Ejemplo n.º 5
0
        public void ApexChartTest_NotNull()
        {
            var chart = new ApexChart(ChartName, Selector, null, formatJson: false);

            Assert.NotNull(chart);
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            var curDir = Directory.GetCurrentDirectory();

            Console.WriteLine($"Current Directory: {curDir}");
            try
            {
                var months = 12;

                var FileName = "democharts.js";

                var chart = new Chart()
                {
                    Height = 350,
                    Type   = ChartType.area,
                    Zoom   = new ChartZoom()
                    {
                        Enabled = true,
                        Type    = ZoomType.x
                    }
                };

                Random r = new Random();

                var series = new List <Serie>()
                {
                    new Serie()
                    {
                        Name = "Data 1",
                        Data = Enumerable.Range(0, months)
                               .Select(x => r.Next(1000))
                               .Select(y => (object)y)
                               .ToArray()
                    },
                    new Serie()
                    {
                        Name = "Data 2",
                        Data = Enumerable.Range(0, months)
                               .Select(x => r.Next(1000))
                               .Select(y => (object)y)
                               .ToArray()
                    }
                };

                var Year = DateTime.Now.Year.ToString();

                var xAxis = new XAxis()
                {
                    Type       = "datetime",
                    Categories =
                        Enumerable.Range(0, months)
                        .Select(i => DateTime.Now.AddMonths(i - months))
                        .Select(date => date.ToString("yyyy-MM-01"))
                        .ToArray <object>()
                };


                var yAxis = new YAxis()
                {
                    Min            = 0,
                    Max            = 1000,
                    ForceNiceScale = true
                };

                var grid = new Grid()
                {
                    Yaxis = new GridYaxis()
                    {
                        Lines = new GridLines()
                        {
                            Show = true
                        }
                    },
                    Xaxis = new GridXaxis()
                    {
                        Lines = new GridLines()
                        {
                            Show = false
                        }
                    }
                };

                var annotations = new Annotations()
                {
                    Yaxis = new List <AnnotationsYaxis>()
                    {
                        new AnnotationsYaxis()
                        {
                            Y           = 0,
                            BorderColor = "grey"
                        }
                    }
                };

                var options = new ChartOptions()
                {
                    Chart      = chart,
                    Series     = series,
                    DataLabels = new DataLabels()
                    {
                        Enabled = false,
                        Style   = new DataLabelsStyle()
                        {
                            FontSize = "8pt",
                            Colors   = new string[] { "black", "black" }
                        }
                    },
                    Colors  = new string[] { "#5bcaff", "#ff82d0" },
                    Markers = new Markers()
                    {
                        Size  = 4,
                        Hover = new MarkersHover()
                        {
                            Size = 6
                        }
                    },
                    Title = new Title()
                    {
                        Text  = "Chart Title",
                        Align = AlignType.left
                    },
                    Grid        = grid,
                    XAxis       = xAxis,
                    YAxis       = yAxis,
                    Annotations = annotations,
                    Stroke      = new Stroke()
                    {
                        Width = 2,
                        Curve = StrokeCurve.straight
                    },
                    Fill = new ChartFill()
                    {
                        Type     = FillType.gradient,
                        Gradient = new ChartFillGradient()
                        {
                            ShadeIntensity = 1,
                            OpacityFrom    = 0.7,
                            OpacityTo      = 0.9,
                            Stops          = new List <int>()
                            {
                                0, 100
                            }
                        }
                    }
                };

                var apexchart = new ApexChart("apexchart", "#ApexChart", options, formatJson: true);

                Console.WriteLine($"Saving Chart to file '{FileName}'");
                File.WriteAllText(FileName, apexchart.ToString());
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.WriteLine($"Starting default browser with 'index.html'");
            Process proc = new Process();

            proc.StartInfo.UseShellExecute = true;
            proc.StartInfo.FileName        = "index.html";
            proc.Start();

            //Console.WriteLine("Press any key...");
            //Console.ReadKey();
        }