我在正确显示我的视图中显示饼图时遇到问题。使用下面的代码,我已经确认字节正在成功写入模型并传递给视图。我甚至确认我可以将饼图保存到视图目录中的PNG文件中,但每次尝试在浏览器中显示饼图时,都不会显示图像。制图显示问题
您会看到我使用了带有饼图的部分视图的索引视图。该计划将在索引视图中呈现多个部分视图。
我希望有人能帮助我克服这一点。提前致谢。
型号:
public byte[] PieChartBytes { get; set; }
public class StatsForPieChart
{
public string dest { get; set; }
public long recordCount { get; set; }
}
控制器:
public ActionResult _DisplayPieChart (model.ViewModel model)
{
ArrayList xSeriesList = new ArrayList();
ArrayList ySeriesList = new ArrayList();
foreach (var item in model.statsforPieChart)
{
xSeriesList.Add(item.dest);
sSeriesList.Add(item.recordCount);
}
model.PieChartBytes = new Chart(width:800, height:600, theme: ChartThem.Blue)
.AddTitle("Title")
.AddLegend()
.AddSeries(
name: "Name",
chartType: "Pie",
xValue: xSeriesList,
yValues: ySeriesList)
.GetBytes("png");
return PartialView(model);
}
索引视图:
Html.RenderAction("_DisplayPieChart", new { model = Model });
饼图:
@{
//the "Save" code is only used to prove the file bytes have been successfully passed and the image is present in the view:
string sImagePath = Server.MapPath("~") + "Content\\" + Guid.NewGuid().ToString + ".png"
WebImage myImage = new WebImage(Model.PieChartBytes);
myImage.Save(sImagePath);
}
<div class="text-center">
<img src="@sImagePath" /> //works in debug mode, but gets blocked on web server - not desired solution.
<img src="@myImage" /> //desired solution, but produces no image.
</div>
两个注意事项:1)我没有看到添加ChartArea的地方,这是数据显示的区域。 2)饼图的X值没有意义。 – TaW
你可以在浏览器上打开该PNG吗? “ – Tony