Asp.net mvc MVC中用户控件上的asp.net图表控件

Asp.net mvc MVC中用户控件上的asp.net图表控件,asp.net-mvc,charts,Asp.net Mvc,Charts,我是MVC框架的新手。我正在MVC框架中从事一个仪表板项目。该项目由母版页中包含的用户控件中的一组图表控件组成。我在aspx页面上的一个图表控件上做了一个测试…它可以工作…但是当我将代码移动到ascx(usercontrol)时,图表无法呈现。有什么想法吗?!?!?!。。。我卡住了。提前谢谢 杰夫 .aspx中的代码 <% System.Web.UI.DataVisualization.Charting.Chart Chart1 = new System.Web.UI.DataVis

我是MVC框架的新手。我正在MVC框架中从事一个仪表板项目。该项目由母版页中包含的用户控件中的一组图表控件组成。我在aspx页面上的一个图表控件上做了一个测试…它可以工作…但是当我将代码移动到ascx(usercontrol)时,图表无法呈现。有什么想法吗?!?!?!。。。我卡住了。提前谢谢

杰夫

.aspx中的代码

 <%
  System.Web.UI.DataVisualization.Charting.Chart Chart1 = new System.Web.UI.DataVisualization.Charting.Chart();
  Chart1.Width = 450;
  Chart1.Height = 296;
  Chart1.RenderType = RenderType.ImageTag;
  Chart1.ImageLocation = "..\\..\\TempImages\\ChartPic_#SEQ(200,30)";

  Chart1.Palette = ChartColorPalette.BrightPastel;
                    Title t = new Title("Program Pipeline", Docking.Top, new System.Drawing.Font("Trebuchet MS", 14, System.Drawing.FontStyle.Bold), System.Drawing.Color.FromArgb(26, 59, 105));
                    Chart1.Titles.Add(t);
                    Chart1.ChartAreas.Add("Prog 1");

  // create a couple of series
                    Chart1.Series.Add("Backlog");
                    Chart1.Series.Add("Constructed");
                    Chart1.Series.Add("Billed");
                    Chart1.Series.Add("BudgetUsed");
                    Chart1.Series.Add("Total");



                    Chart1.Series["Backlog"].ChartType = SeriesChartType.StackedBar100;
                    Chart1.Series["Constructed"].ChartType = SeriesChartType.StackedBar100;
                    Chart1.Series["Billed"].ChartType = SeriesChartType.StackedBar100;
                    Chart1.Series["Total"].ChartType = SeriesChartType.StackedBar100;
                    Chart1.Series["BudgetUsed"].ChartType = SeriesChartType.StackedBar100;

                    Chart1.Series["Backlog"]["DrawingStyle"] = "Cylinder";
                    Chart1.Series["Constructed"]["DrawingStyle"] = "Cylinder";
                    Chart1.Series["Billed"]["DrawingStyle"] = "Cylinder";
                    Chart1.Series["BudgetUsed"]["DrawingStyle"] = "Cylinder";
                    Chart1.Series["Total"]["DrawingStyle"] = "Cylinder";


                    // Bar Size
                    Chart1.Series["Backlog"]["PointWidth"] = "0.6";
                    Chart1.Series["Constructed"]["PointWidth"] = "0.6";
                    Chart1.Series["Billed"]["PointWidth"] = "0.6";
                    Chart1.Series["BudgetUsed"]["PointWidth"] = "0.6";
                    Chart1.Series["Total"]["PointWidth"] = "0.6";




                    int _total = 0;
                    int _newTotalAmt = 100 - _total;
                    foreach (MvcApplication1.Models.Amount obj in Model.GetTotalAmt("plm1"))
                    {
                        _total += obj.TotalAmount;

                        Chart1.Series[obj.PLMType].Points.AddY(obj.TotalAmount);
                    }
                    Chart1.Series["BudgetUsed"].Points.AddY(0);
                    Chart1.Series["Total"].Points.AddY(_newTotalAmt);



                    _total = 0;
                    _newTotalAmt = 100 - _total;
                    foreach (MvcApplication1.Models.Amount obj in Model.GetTotalAmtForPLM2("plm2"))
                    {
                        _total += obj.TotalAmount;

                        Chart1.Series[obj.PLMType].Points.AddY(obj.TotalAmount);
                    }
                    Chart1.Series["BudgetUsed"].Points.AddY(0);
                    Chart1.Series["Total"].Points.AddY(_newTotalAmt);




                    _total = 0;
                    _newTotalAmt = 100 - _total;
                    foreach (MvcApplication1.Models.Amount obj in Model.GetTotalAmt("plm3"))
                    {
                        _total += obj.TotalAmount;

                        Chart1.Series[obj.PLMType].Points.AddY(obj.TotalAmount);
                    }
                    Chart1.Series["BudgetUsed"].Points.AddY(0);
                    Chart1.Series["Total"].Points.AddY(_newTotalAmt);



                  // MvcApplication1.Models.TotalPOAmount oTotal = Model.GetOverAllBudget();



                    // add points to series 3
                    Chart1.Series["Billed"].Points.AddY(0);
                    Chart1.Series["Constructed"].Points.AddY(0);
                    Chart1.Series["Backlog"].Points.AddY(0);
                    Chart1.Series["BudgetUsed"].Points.AddY(39);
                    Chart1.Series["Total"].Points.AddY(100);



  Chart1.BorderSkin.SkinStyle = BorderSkinStyle.Emboss;
  Chart1.BorderColor = System.Drawing.Color.FromArgb(26, 59, 105);
                    Chart1.BorderlineDashStyle = ChartDashStyle.Solid;
  Chart1.BorderWidth = 2;

                    Chart1.Legends.Add("Legend");

      // show legend based on check box value
                  //  Chart1.Legends["Legend1"].Enabled = ShowLegend.Checked;

  // Render chart control
  Chart1.Page = this;
  HtmlTextWriter writer = new HtmlTextWriter(Page.Response.Output);
  Chart1.RenderControl(writer);


                    //IList<SelectListItem> list = new List<SelectListItem>();
                    //SelectListItem sli = new SelectListItem();
                    //sli.Text = "test1";
                    //sli.Value = "1";

                    //list.Add(sli);
                    //ViewData["Test"] = list;


                 %>

我遇到了完全相同的问题。我的问题与图像文件的路径有关。图表控件放置在usercontrol上时出错。如果我将图表更改为使用HttpHandler的Imagestoragemode,那么它将按预期工作


不幸的是,这使我无法对我的视图进行单元测试。最后,我将图表控件放在一个aspx页面上&然后在需要时使用jQuery加载它。(幸运的是,我的仪表板页面使用javascript加载portlet的内容)

我一直在尝试解决似乎同样的问题。当我将代码(类似于上面的代码)移动到UserControl时,System.Web.UI.DataVisualization命名空间未被识别,我收到了错误:

类型或命名空间名称 中不存在“DataVisualization” 名称空间“System.Web.UI”(您是 缺少程序集引用?)

只有当图表代码位于asp控件中时(在aspx页面中,它位于控件中),名称空间才被识别。所以我把图表代码放在一个控件中,它就工作了