asp.net mvc - MVC Charts - Passing data from one view to another cshtml -
working within existing mvc app creating various charts display client data. i'm entirely new charts in asp.net. i'm using http://www.asp.net/web-pages/overview/data/7-displaying-data-in-a-chart resource creating charts.
currently creating charts fine, , typically x values fixed (e.g. jan, feb, mar, apr etc.) , y values found querying list sent view.
the chart objects i'm creating create image, thing displayed on page, , layout lost result obviously.
the article mentions embedding in web page calling chart separate view like:
<body> <p><img src="chartarraybasic.cshtml" /> </p> </body>
as generating charts querying list in view variable values, in order make them more general chart views can used clients own data, need .cshtml file call receive list.
is possible to: 1. call view action method. 2. view displays regular page view embedded in it. 3. embedded view needs receive list object initial view.
thanks, jk
@jonnyknottsvill answered here exception, advised above, create partialview can reuse later want.
_chartparialview.cshtml
in shared folder inside views:
@model ienumerable<string> @{ var mychart = new chart(width: 600, height: 400) .addtitle("chart title") .addseries( name: "employee", xvalue: new[] { "peter", "andrew", "julie", "mary", "dave" }, yvalues: model) .write(); }
the controller:
public class homecontroller : controller { public actionresult index() { return view(); } public actionresult drawchart() { var model = new[] { "2", "6", "4", "5", "3" }; return partialview("_chartpartialview", model); } }
the home(index) view want chart rendered image:
@{ viewbag.title = "chart"; } <h2>chart</h2> <img src="@url.action("drawchart")" />
Comments
Post a Comment