繁体   English   中英

如何将数据从模型(MVC)传递到@ url.Action()以绘制图表

[英]How to pass data from a model (MVC) to @url.Action() to plot a chart

我想绘制一个饼图。 图表数据位于模型/控制器中。 我有一个@Url.Action()显示饼图。 如何在这里将图表数据从模型传递到@Url.Action() -最终在饼图上绘制该数据?

我是MVC方法和C#的新手。 任何帮助将不胜感激。

MyHtml.cshtml

@model Project.Models.Data

<body>
    <!-- Display Chart in Partial View Ctrl -->
    <!-- Url.Action ( <ActionName>, <Controller Name> ) -->
    <p><img src="@Url.Action("ShowChart","AssetHistory")" alt="Chart" /> </p>
</body>

Controller.cs

// Partial View for Pie Chart
        public ActionResult ShowChart()
        {
            var ChartData = new[] { "95", "5" }; // hard coded data //

//            return PartialView("Chart");
            return PartialView ( "Chart", ChartData );
        }

MakeChart.cshtml

@* @model Project.Models.Data *@
@model IEnumerable<string>

<!-- Model Data Inherited from Parent View  ?? -->

@{
    var myChart = new Chart(width: 600, height: 400)
    .AddTitle("Overall Equipment Effectiveness")
    .AddSeries(
        chartType: "Pie",
        name: "OEE",
        xValue: new[] { "ON", "OFF" },
 @*       yValues: new[] { "25", "75" } ) *@
        yValues: Model)
    .Write();
}

我已经回答了类似的问题。 请参阅以下链接:

使用条形图工作(我认为这会更适合您的需求)

第二个链接也带有条形图

希望这可以帮助!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM