@using Trirand.Web.Core
@using System.Collections.Generic;
@using Trirand.Web.Core.Chart;
@using Trirand.Web.Core.Chart.Series;
@using Trirand.Web.Core.Chart.Series.Data;

<!DOCTYPE html>
<html lang="en-us">
<head>
    <meta charset="utf-8">
    <title>Chart for ASP.NET Core - Doughnut Simple</title>  
    <script type="text/javascript" src="~/js/trirand/chart/corechart.min.js"></script>
</head>
<body>
    <div>
        <!--
        The Html.Trirand().CoreChart() helper has two parameters
            - the model of the chart -- all chart properties, data and settings
            - the ID of the chart -- can be used for client-side manipulation
        In this example we are using hardcoded model in the View, but you can contruct the model in 
        the controller based on runtime criteria and database data and pass the model 
        to the View using ViewData
        -->
        @(Html.Trirand().CoreChart(
            new CoreChart
            {
                Title = new List<Title>
                {
                    new Title()
                    {
                        Left = "center",
                        Text = "Customized Pie",
                        Top = 20,
                        TextStyle = new Trirand.Web.Core.Chart.Style.TextStyle
                        {
                            Color = "#ccc"
                        }
                    }
                },
                Tooltip = new ToolTip
                {
                    Trigger = TriggerType.Item,
                    Formatter = "{a} <br/>{b} : {c} ({d}%)"
                },
                Legend = new Legend
                {
                    Orient = OrientType.Vertical,
                    Left = "left",
                    Data = ViewData["legendData"] as List<string>,

                },

                Series = new List<object>()
                {
                    new Pie()
                    {
                        Name = "Access Source",
                        Radius = new List<string> { "50%" , "70%" },
                        Data = ViewData["pieData"] as List<PieData<int>>,
                        AvoidLabelOverlap = false  
                    },
                }
            }
            , "Chart")
        )
             
        <br />
        <div>
            @await Component.InvokeAsync("CodeTabs", new { product = "chart", example = "doughnut/simpledoughnut" })
        </div>
    </div>
</body>
</html>

using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using Trirand.Web.Core.Chart.Series.Data;

namespace CoreDemo.Controllers.Chart
{
    public partial class ChartController : Controller
    {
        [Route("chart/doughnut/simpledoughnut")]
        public ActionResult SimpleDoughnut()
        {
            List<PieData<int>> pieData = new List<PieData<int>>
            {
                new PieData<int> { Name = "Interview", Value = 335},
                new PieData<int> { Name = "Mail", Value = 310},
                new PieData<int> { Name = "Affiliate", Value = 274},
                new PieData<int> { Name = "Video", Value = 235},
                new PieData<int> { Name = "Search", Value = 400}
            };

            List<string> legendData = new List<string>() { "Interview", "Mail", "Affiliate", "Video", "Search" };

            ViewData["pieData"] = pieData;
            ViewData["legendData"] = legendData;

            return View("~/Views/Chart/doughnut/simpledoughnut.cshtml");
        }
    }
}