vs2010 MVC调用msChart问题

VS2010 MVC 调用MSChart时,用<img src="/HOME/GetChart"> 实现没问题。

另外一种方式:在VIEW中使用如下代码:

<%
        Chart Chart2 
= new Chart();
        Chart2.Width 
= 412;
        Chart2.Height 
= 296;
        Chart2.RenderType 
= RenderType.ImageTag;
        Chart2.Palette 
= ChartColorPalette.BrightPastel;
        Title t 
= new Title("No Code Behind Page", Docking.Top, new System.Drawing.Font("Trebuchet MS"14, System.Drawing.FontStyle.Bold), System.Drawing.Color.FromArgb(2659105));
        Chart2.Titles.Add(t);
        Chart2.ChartAreas.Add(
"Series 1");
        
// create a couple of series
        Chart2.Series.Add("Series 1");
        Chart2.Series.Add(
"Series 2");
        
// add points to series 1
        foreach (int value in (List<int>)ViewData["Chart"])
        {
            Chart2.Series[
"Series 1"].Points.AddY(value);
        }
        
// add points to series 2
        foreach (int value in (List<int>)ViewData["Chart"])
        {
        Chart2.Series[
"Series 2"].Points.AddY(value + 1);
        }
        Chart2.BorderSkin.SkinStyle 
= BorderSkinStyle.Emboss;
        Chart2.BorderColor 
= System.Drawing.Color.FromArgb(2659105);
        Chart2.BorderlineDashStyle 
= ChartDashStyle.Solid;
        Chart2.BorderWidth 
= 2;
        Chart2.Legends.Add(
"Legend1");
        
// Render chart control
        Chart2.Page = this;
        HtmlTextWriter writer 
= new HtmlTextWriter(Page.Response.Output);
        Chart2.RenderControl(writer);
    
%>

HomeController:

        public ActionResult About()
        {
            List
<int> chartList = new List<int>();
            chartList.Add(
1);
            chartList.Add(
2);
            chartList.Add(
6);
            chartList.Add(
5);
            chartList.Add(
4);

            ViewData[
"Chart"= chartList;

            
return View();
        }

查看源文件:控件被生成为一个图片,图片的src如下:

<img src="/Home/ChartImg.axd?i=chart_3a3c22f8ad774c3a9c765a531b51f334_0.png&amp;g=c2c46849320a42b1ac821756bacadb31" alt="" style="height:296px;412px;border-0px;" />

 
此时图片是显现不出来的。为一个叉叉。不明白什么原因。

将同样的代码在vs2008实现,控件被生成为一个图片,图片的src如下:

<img src="/ChartImg.axd?i=chart_adabc7b50f574ce3a16a2cfdb6855af0_1.png&amp;g=db21ec7883804c238a3e7fc3b0b6443d" alt="" style="height:296px;412px;border-0px;" />

曲线正常显示。。。。。。这究竟是什么原因呢。然后在vs2010上做修改。将所有web.config中mschart的相关配置设置从4.0.0.0改成3.5.0.0

曲线又正常显示了。

在MVC中添加一个webform来实现mschart,因为项目中的需求有用户与曲线交互,即需要点击曲线上的点,不会在MVC上实现,准备在MVC项目上增加一个webform来做,可是问题又来了,.net 4.0里自带了一个System.Web.UI.DataVisualization,以上的问题再次出现了,曲线图片仍然显示不出来。感觉还是.net 4的原因,于是又在引用准备添加C:\Program Files\Microsoft Chart Controls\Assemblies中的System.Web.UI.DataVisualization,可每次添加完后都是4.0的dll,无赖跑去删除了4.0的System.Web.UI.DataVisualization的dll。MVC中的webform的MSChart又出现了。这究竟是什么原因呢?

原文地址:https://www.cnblogs.com/Godblessyou/p/2058850.html