[英]"Object reference not set to an instance of an object" while making chart in ASP.NET MVC view (Razor code)
I tried adding a pie chart in my view using ASP.NET MVC and I am getting an error我尝试使用 ASP.NET MVC 在我的视图中添加饼图,但出现错误
Object reference not set to an instance of an object
Object 引用未设置为 object 的实例
at line 4 in the code where I create a new chart.在我创建新图表的代码的第 4 行。
Here is my code in the view:这是我在视图中的代码:
@model ProjectViewModel
@{
ViewBag.Title = "DashBoard";
Chart myChart = new Chart(width: 600, height: 400)
.AddTitle("Projects")
.AddSeries("Default", chartType: "Pie",
xValue: Model.Names, xField: "Name",
yValues: Model.Values, yFields: "Sales")
.Write();
}
Can somebody please tell me the solution?有人可以告诉我解决方案吗?
This error you will get once the x or y values is null make sure you have values in x and y一旦 x 或 y 值为 null ,您将收到此错误,请确保您在 x 和 y 中有值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.