Note that there are some explanatory texts on larger screens.

plurals
  1. PODisplaying ASP.NET Chart controls in ASP.NET MVC site with virtual path
    primarykey
    data
    text
    <p>I have a simple project that combines ASP.NET MVC with ASP.NET Charts control. Code is super simple and works IF I do not specify any "Virtual Path" when I run it in VS 2008. I followed Mike Ceranski post on his blog here: <a href="http://www.codecapers.com/post/Build-a-Dashboard-With-Microsoft-Chart-Controls.aspx" rel="nofollow noreferrer">http://www.codecapers.com/post/Build-a-Dashboard-With-Microsoft-Chart-Controls.aspx</a></p> <p>But, if I put a virtual path (in the "Web" tab in project properties), it will fail and produce this error: Failed to map the path '/ChartImg.axd'. So it seems that it is still looking to call ChartImg.axd in the root directory instead of inside the virtual path. </p> <p>So, my question is - how do I get it to go to the virtual path instead?</p> <p>I have also done where the controller's action just return the image filestream - which I don't want - since eventually I want to be able to make the chart clickable instead of just a plain image.</p> <p>Here is my web.config settings related to ASP.NET Chart:</p> <pre><code>&lt;appSettings&gt; &lt;add key="ChartImageHandler" value="storage=file;timeout=20;URL=/App_Data/MicrosoftChartControls/"/&gt; &lt;/appSettings&gt; &lt;httpHandlers&gt; ... &lt;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"/&gt; &lt;/httpHandlers&gt; </code></pre> <p>Code for the controller:</p> <pre><code>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 &lt; 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; } </code></pre> <p>Code for the aspx:</p> <pre><code>&lt;% supportChart.Controls.Add(ViewData["Chart"] as Chart); %&gt; &lt;asp:Panel ID="supportChart" runat="server"&gt;&lt;/asp:Panel&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload