tia*_*o92 0 c# asp.net-mvc razor
我试图在我的mvc应用程序上显示一些图表,但我有一些错误.我正在开发localhost.我有一个名为ReportChart的cshtml文件
@{
var myChart = new Chart(width: 600, height: 400)
.AddTitle("Chart Title")
.AddSeries(
name: "Employee",
xValue: new[] { "Peter", "Andrew", "Julie", "Mary", "Dave" },
yValues: new[] { "2", "6", "4", "5", "3" })
.Write();
Run Code Online (Sandbox Code Playgroud)
}
和另一个使用该图表的文件:
<body>
<h1>Chart Example</h1>
<p>The following chart is generated by the <em>ReportChart.cshtml</em> file:</p>
<p><img src="ReportChart.cshtml" alt="Cricketers" /> </p>
Run Code Online (Sandbox Code Playgroud)
唯一的问题是网页不显示任何图像:/
不,它不适用于MVC.您应该在控制器操作方法中创建图表:
//I CUT THE CODE WHERE I construct string[] t1 and int[] t2 these are just arrays
public ActionResult EfficiencyChart(string pid) {
var myChart = new Chart(width: 1000, height: 600)
.AddTitle("Employee's Efficiency")
.AddSeries(
name: "Employee",
xValue: t2,
yValues: t1)
.Write();
myChart.Save("~/Content/chart" + user.Id, "jpeg");
// Return the contents of the Stream to the client
return base.File("~/Content/chart" + user.Id, "jpeg");
}
Run Code Online (Sandbox Code Playgroud)
然后在Razor视图中:
<img src="@Url.Action("EfficiencyChart", "NAME_OF_THE_CONTROLLER", new { pid = @Model.Id })" />
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3910 次 |
| 最近记录: |