我是新手,现在我正试图用MVC显示图表。
显示图表有两种可能性:
目前,我尝试使用此代码:
控制器:
[HttpPost]
public ActionResult RenderRainfallChart()
{
var incomeList = Income.GetList();
List<string> xValue = new List<string>();
List<decimal> yValue = new List<decimal>();
foreach (var item in incomeList)
{
xValues.Add(item.Name);
yValues.Add(item.Amount);
}
var key = new System.Web.Helpers.Chart(width: 600, height: 400)
.AddSeries(
legend: "IncomeLIst",
xValue: xValue,
yValues: yValues)
.Write();}
选择按钮后,图表将显示在新的浏览页面上:... / Company / RenderRainfallChart
是否可以在索引网站的div容器中显示图表?
答案 0 :(得分:0)
谷歌图表API可能吗?它使用JavaScript,因此您必须在页面中写入值或使用AJAX检索它们。
答案 1 :(得分:0)
对于非交互式图表,您可以进行一次GET获取图表的图像,然后在您的网页中,您只需添加指向该网址的<img>
。
您可以使用以下内容获取图表图像的字节:
byte[] GetBytes(Chart chart, ChartImageFormat imageFormat)
{
using (var stream = new MemoryStream())
{
chart.SaveImage(stream, imageFormat);
return stream.ToArray();
}
}