Sign in to follow this  
mganley2000

Mvc3 Areas And Working Charts?

Recommended Posts

What is the correct approach to reference the Data.xml file from a view within the MVC 3 Areas folder? I cannot get a chart to display (the flash version), nor the debug window to display, when I attempt to reference the "../Data.xml" from within a Areas in my MVC3 test project. The javascript version of the chart works - sort of.

 

The same seems to work okay when I am NOT within an MVC Area, except that the Javascript rendered charts seem somewhat off. Like bars to not display correctly after the animation completes...

 

Anyone have success with FusionCharts in MVC3. Seems like it should be working...

Share this post


Link to post
Share on other sites

That MVC3 sample validates what I did at the root level. But it does not use Areas. But, I did figure out the issue when Areas are in-play. I have to adjust the path to the SWF file when I am adding the chart javascript when I am in a particular view within an area. Seems simple, now that I have it figured out.

 

Basically, if you have defined an area name "Demo", so that it essentially lives within the Areas folder. And, say your controller is "HomeController", and your view is "Home", action is "Index", you would reach that page with one of these URL's, for example (given that you route this correctly.)

 

www.mysite.com/MyApp/Demo/Home

www.mysite.com/MyApp/Demo/Home/Index

 

 

To allow that path to render a chart you have place on your page in Flash, the path to your FusionCharts folder off your root would need to be as shown here:

  var myChart = new FusionCharts("../../FusionCharts/Line.swf", "myChartId", "400", "300", "0", "1"); 

 

If you did NOT use Areas, and your URL was straight to a Home controller, your path would have just been:

  var myChart = new FusionCharts("FusionCharts/Line.swf", "myChartId", "400", "300", "0", "1"); 

 

 

****

And, I realized, that if you are forcing pure javascript/HTML5 rendering, it simply parses the chart type from that first argument. You can simply provide "Line", and you get a line chart. Not sure if that is documented. Probably not, since it desires the full path if you let it run normally with Flash as the first choice.

****

Share this post


Link to post
Share on other sites

Well, I finally got the razor syntax correct in MVC. This gets the correct path for the chart, no matter whether the chart originates from an Area or from the root.

 

 var myChart = new FusionCharts('@Url.Content("~/FusionCharts/Line.swf")', "myChartId", "400", "300", "0", "1");  

 

That is all. Crisis averted.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this