views:

1339

answers:

2

Hello Fellow Developers,

I am new to the MVC Framework. Im working on a dashboard project in the MVC framework. The project consists of a bunch of charting control in a user controls contained in a master page. I did a test on a charting control on a aspx page..and it works...but when I moved the code to a ascx (usercontrol) the chart doesnt render. Any ideas?!?!?!...I'm stuck. Thanks in advance

Jeff

Code that is in in the .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;


                 %>
+1  A: 

I've had exactly the same issue. My problem was to do with the paths to the image file. The chart control was getting it wrong when placed on a usercontrol. If I changed the chart to use Imagestoragemode of HttpHandler then it worked as intended.

unfortunatly this stopped me being able to unit test my views. In the end I put the chart control on an aspx page & then used jQuery to load it when needed. (Luckily my dashboard page used javascript to load the contents of the portlets)

Jon Spokes
+1  A: 

Hi Jeff,
I've just been trying to get round what seems to be the same problem. When I moved the code (similar to yours above) to a UserControl the System.Web.UI.DataVisualization namespace wasn't recognised and I received the error:

The type or namespace name 'DataVisualization' does not exist in the namespace 'System.Web.UI' (are you missing an assembly reference?)

The namespace only seemed to be recognised when the Chart code lay within an asp control (in the aspx page it was within an <asp:Content> control). So I put the Chart code within an <asp:Panel> control and it worked.

Ross
this got it working for me too, thanks
fearofawhackplanet