我想将Session [CountryList“]用于数据源报告图表。
我添加了我的图表报告,但是没有代码。
如何将Session [CountryList“]添加为数据源并在报告图表中显示?
型号:
public static IList<Country> GetCountries()
{
return new List<Country>(){
new Country("Russia", 50),
new Country("Canada", 231),
new Country("USA", 33),
new Country("China", 111),
new Country("Brazil", 14),
new Country("Australia", 140),
new Country("India", 434),
new Country("Turkey", 3),
new Country("England", 21),
new Country("Greece", 116)
};
}
}
public class Country
{
string name;
double area;
public string Name { get { return name; } }
public double Area { get { return area; } }
public Country(string name, double area)
{
this.name = name;
this.area = area;
}
}
控制器:
public ActionResult ReportViewerPartial()
{
Session["CountriesDatas"] = CountriesProvider.GetCountries(); //Country List
XtraReport1 report = new Q502351.Reports.XtraReport1();
report.DataSourceDemanded += report_DataSourceDemanded;
ViewData["Report"] = report;
return PartialView("ReportViewerPartial");
}
答案 0 :(得分:0)
我尝试使用您的模型数据。
以下代码也适用于您。
public ActionResult ExportReportViewer()
{
XtraReport1 report = new CrmSoner.Reports.XtraReport1();
XRChart chart = report.FindControl("xrChart1", true) as XRChart;
List<Country> list = Session["CountriesDatas"] as List<Country>;
chart.DataSource = list;
chart.Series[0].ArgumentDataMember = "Name";
chart.Series[0].ValueDataMembers.Clear();
chart.Series[0].ValueDataMembers.AddRange(new string[] { "Area" });
return DevExpress.Web.Mvc.ReportViewerExtension.ExportTo(report);
}