среда, 20 августа 2025 г.

RazorPage, Project, ChartDirector, Sine

RazorPage, Project, ChartDirector, Sine

D:\VC2508\Charts\WpfChartSln\WpfChartDir\WpfChartDir.sln

D:\VC2508\Charts\WpfChartSln\WpfChartDir\RazorChartDirApp07\RazorChartDirApp07.csproj

ChartDirector, Синусоида, work well

Page work well

---------------------------------------------------------------------------
SimpleLine.cshtml

@* @page

@model RazorChartDirApp07.Pages.SimpleLineModel

@{

} *@


@page

@model SimpleLineModel

@using ChartDirector

@{

    Layout = "_Layout";

}


@{

    if (ViewBag.Viewer is Array)

    {

        // Display multiple charts

        for (int i = 0; i < ViewBag.Viewer.Length; ++i)

        {

            @:@Html.Raw(ViewBag.Viewer[i].RenderHTML())

        }

    }

    else

    {

        // Display one chart only

        @:@Html.Raw(ViewBag.Viewer.RenderHTML())

    }

}


@section Scripts {

    <script>

        setTimeout(function () { window.location.reload(); }, 1000);

    </script>

}

-------------------------------
SimpleLine.cshtml.cs
------------------------------

using ChartDirector;

using LinSpace;

using Microsoft.AspNetCore.Mvc;

using Microsoft.AspNetCore.Mvc.RazorPages;

using RazorChartDirApp07.Services;


namespace RazorChartDirApp07.Pages

{

    public class SimpleLineModel : PageModel

    {

        private readonly IRunningSineState _state;

        private readonly ILogger<IndexModel> _logger;


        public SimpleLineModel(IRunningSineState state, ILogger<IndexModel> logger)

        {

            _state = state;

            _logger = logger;

        }

        public void OnGet()

        {

            ViewData["Title"] = "Simple Line Chart";

            RazorChartViewer viewer = new RazorChartViewer(HttpContext, "chart1");

            ViewData["Viewer"] = viewer;

            createChart(viewer);

        }

        private void createChart(RazorChartViewer viewer)

        {

            _logger.Log(LogLevel.Information, "CurrentIndex: " + _state.CurrentIndex.ToString());

            var dataArg = MathSeries.Linspace(0.0, 2 * Math.PI, 36, _state.CurrentIndex);

            var data = MathSeries.Evaluate(dataArg, Math.Sin);

            var nextIndex = _state.NextIndex(36);

            _logger.Log(LogLevel.Information, "CurrentIndex: " + _state.CurrentIndex.ToString());

            // The labels for the line chart

            string[] labels = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12",

                                "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24",

                                "25", "26", "27","28", "29", "30", "31","32","33", "34", "35"};


            // Create a XYChart object of size 250 x 250 pixels

            XYChart c = new XYChart(450, 450);


            // Set the plotarea at (30, 20) and of size 200 x 200 pixels

            c.setPlotArea(30, 20, 400, 400);


            // Add a line chart layer using the given data

            c.addLineLayer(data);


            // Set the labels on the x axis.

            c.xAxis().setLabels(labels);


            // Display 1 out of 3 labels on the x-axis.

            c.xAxis().setLabelStep(3);


            // Output the chart

            viewer.Image = c.makeWebImage(Chart.SVG);


            // Include tool tip for the chart

            viewer.ImageMap = c.getHTMLImageMap("", "",

                "title='Hour {xLabel}: Traffic {value} GBytes'");

        }

    }

}


Комментариев нет:

Отправить комментарий