私のビューに円グラフを正しく表示させることに問題があります。以下のコードでは、バイトがモデルに正常に書き込まれ、ビューに渡されていることを確認しました。私は、ビューからディレクトリ内の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>
2つのノート:1)データが表示されている領域であるChartAreaをどこに追加するかわかりません。 2)円グラフのX値は無意味です。 – TaW
ブラウザでそのPNGを開くことはできますか? – Tony