C# 如何将数组值传递给图表';s属性,即xValue和yValue
我想在我的网页上显示图表,但我得到的输出是下面给出的输出图像,当我直接在图表的xValue和yValue中传递数组时,它会给我下面给出的预期reslut,但当我从我的值传递这些值时,它会给出下面给出的输出图像结果C# 如何将数组值传递给图表';s属性,即xValue和yValue,c#,asp.net-mvc,C#,Asp.net Mvc,我想在我的网页上显示图表,但我得到的输出是下面给出的输出图像,当我直接在图表的xValue和yValue中传递数组时,它会给我下面给出的预期reslut,但当我从我的值传递这些值时,它会给出下面给出的输出图像结果 public ActionResult GetChartImage(string Title, string[] xValue, string[] yValue) { var key = new Chart(width: 300, height: 300) .A
public ActionResult GetChartImage(string Title, string[] xValue, string[] yValue)
{
var key = new Chart(width: 300, height: 300)
.AddTitle("Employee Chart")
.AddSeries(
chartType: "column",
name: "Employee",
xValue: xValue,
yValues: yValue);
return File(key.ToWebImage().GetBytes(), "image/jpeg");
}
这里是一个视图
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
<div>
<div>
@{
string[] names = { "Peter", "Andrew", "Julie", "Dave" };
string[] numbers = { "2", "7", "5", "3" };
}
<img src="@Url.Action("GetChartImage", new { Title = "Bar-Code", xValue = names, yValue = numbers })" />
</div>
</div>
</body>
</html>
试验
@{
字符串[]名称={“彼得”、“安德鲁”、“朱莉”、“戴夫”};
字符串[]数字={“2”、“7”、“5”、“3”};
}
这是一个输出图像
但是我想要这个
如果查看生成的html,将看到
..&xValue=System.String[]&yValue=System.String[]
您需要将值传递为&xValue=Peter&xValue=Andrew…
等,比如说…IEnumerable xValue,String xField,IEnumerable yValue,String yFields
,但是为什么要在视图中硬编码值呢。您也可以只在GetChartImage()
方法中分配这些值。您无法使用路由值传递集合-助手使用您提供的值的.ToString()
方法,在string[]
的情况下,它是“System.string[]”
(不是集合中的值)。但是,同样,如果值在数据库中,则通过GetChartImage()
方法从数据库中获取它们-将它们放在视图中没有任何意义。但是我将使用entityframework从数据库中传递值。对在您的操作方法中,在GetChartImage
方法中,您应该接受一个唯一的ID(例如:empoyeId),您可以使用该ID从db派生数据并将其传递到图表,而不是接受数组。