ASP.NET MVC と ASP.NET Charts コントロールを組み合わせた単純なプロジェクトがあります。コードは非常にシンプルで、VS 2008 で実行するときに "仮想パス" を指定しなければ機能します。 Dashboard-With-Microsoft-Chart-Controls.aspx
しかし、(プロジェクト プロパティの [Web] タブに) 仮想パスを配置すると失敗し、次のエラーが発生します: パス '/ChartImg.axd' をマップできませんでした。そのため、仮想パス内ではなく、ルート ディレクトリで ChartImg.axd を呼び出しようとしているようです。
だから、私の質問は - 代わりに仮想パスに移動するにはどうすればよいですか?
また、コントローラーのアクションが画像ファイルストリームを返すだけの場合も実行しましたが、これは望ましくありません。最終的には、単なる画像ではなくチャートをクリック可能にしたいからです。
ASP.NET チャートに関連する私の web.config 設定は次のとおりです。
<appSettings>
<add key="ChartImageHandler" value="storage=file;timeout=20;URL=/App_Data/MicrosoftChartControls/"/>
</appSettings>
<httpHandlers>
...
<add verb="*" path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
</httpHandlers>
コントローラーのコード:
public ActionResult Index() {
ViewData["Message"] = "Welcome to ASP.NET MVC!";
ViewData["Chart"] = BindChartData();
return View();
}
private Chart BindChartData() {
Chart chart = new Chart();
chart.Width = 150;
chart.Height = 300;
chart.Attributes.Add("align", "left");
chart.Titles.Add("MY CHART");
chart.ChartAreas.Add(new ChartArea());
chart.Series.Add(new Series());
chart.Legends.Add(new Legend("MY CHART"));
chart.Legends[0].TableStyle = LegendTableStyle.Auto;
chart.Legends[0].Docking = Docking.Bottom;
for (int i = 0; i < 10; i++) {
string x = ChartTest.Models.Utility.RandomText();
decimal y = ChartTest.Models.Utility.RandomNumber(1, 100);
int ptIdx = chart.Series[0].Points.AddXY(x, y);
DataPoint pt = chart.Series[0].Points[ptIdx];
pt.LegendText = "#VALX: #VALY";
}
chart.Series[0].Legend = "MY CHART";
return chart;
}
aspx のコード:
<%
supportChart.Controls.Add(ViewData["Chart"] as Chart);
%>
<asp:Panel ID="supportChart" runat="server"></asp:Panel>