使用来自这篇文章的从控制器生成图像的答案,我创建了一个控制器操作来返回一个图表图像,如下所示(X 和 Y 值只是作为测试数据存在):
public FileContentResult HistoryChart()
{
Chart chart = new Chart();
string[] currencies = { "ZAR", "USD", "GBP", "JPY" };
foreach (string currency in currencies)
{
Series series = new Series(currency);
series.ChartType = SeriesChartType.FastLine;
for (int x = 0; x <= 30; x++)
series.Points.AddXY(x, (x * 5));
chart.Series.Add(series);
}
using (MemoryStream ms = new MemoryStream())
{
chart.SaveImage(ms, ChartImageFormat.Png);
ms.Seek(0, SeekOrigin.Begin);
return File(ms.ToArray(), "image/png", "mychart.png");
}
}
问题是,控制器返回的图像是空白的(尽管它确实返回了图像)
我希望我遗漏了一些简单的东西!任何输入将不胜感激,谢谢。