最近写了一个ajax控件刷新静态页面中一个图片,因为好久没写这个东西了,出现了一个错误,请各位指点指点
   页面文件
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %><%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="System.Web.UI" TagPrefix="asp" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>动态显示水位平衡</title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
    <div>
        <asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Interval="10000">
        </asp:Timer>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:Image ID="Image1" runat="server"/></ContentTemplate>
        <Triggers>
       <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
       <asp:PostBackTrigger ControlID="DropDownList1" />
        </Triggers>
        </asp:UpdatePanel>
        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
        </asp:DropDownList>
    </div>
    </form>
</body>
</html>
后台文件:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.Office.Interop.Owc11;
using System.Collections.Generic;public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //AjaxPro.Utility.RegisterTypeForAjax(typeof(Default2));
        if (!IsPostBack)
        {
            string[] chartType = new string[3] { "曲线图", "饼图", "柱状图" };
            this.DropDownList1.DataSource = chartType;
            this.DropDownList1.DataBind();
            Image1.ImageUrl = getNewPic(this.DropDownList1.SelectedValue.ToString());
        }
    }
    
    public string getNewPic(string chartType)
    {
        //创建ChartSpace对象来放置图表
        //Microsoft.Office.Interop.Owc11.ChartSpace objCSpace2=
        Microsoft.Office.Interop.Owc11.ChartSpace objCSpace = new Microsoft.Office.Interop.Owc11.ChartSpaceClass();
        //objCSpace.Clear();
        //在ChartSpace对象中添加图表,Add方法返回chart对象
        Microsoft.Office.Interop.Owc11.ChChart objChart = objCSpace.Charts.Add(0);
        if (chartType == "曲线图")
        //指定图表的类型。类型由OWC.ChartChartTypeEnum枚举值得到
        {
            objChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeSmoothLineMarkers;
            objChart.Axes[1].HasTitle = true;
            objChart.Axes[1].Title.Caption = "Y : 数量";
            objChart.Axes[0].HasTitle = true;
            //objChart.Axes[0].Scaling.SplitMinimum = 200;
            objChart.Axes[0].Title.Caption = "X : 月份";
        }
        if (chartType == "饼图")
        {
            objChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypePie3D;
            //显示百分比 
                   }
        if (chartType == "柱状图")
        {
            objChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeColumnClustered;
            objChart.Axes[1].HasTitle = true;
            objChart.Axes[1].Title.Caption = "Y : 数量";            objChart.Axes[0].HasTitle = true;
            //objChart.Axes[0].Scaling.SplitMinimum = 200;
            objChart.Axes[0].Title.Caption = "X: 月份";
        }
        //指定图表是否需要图例
        objChart.HasLegend = true;        //给定标题
        objChart.HasTitle = true;
        objChart.Title.Caption = "上半年分布图";
        
        //计算数据
        /*categories 和 values 可以用tab分割的字符串来表示*/
        string strSeriesName = "单位 万元";
        string strCategory = "一月份" + "\t" + "二月份" + '\t' + "三月份" + '\t' + "四月份" + '\t' + "五月份" + '\t' + "六月份";
        //string strValue = "30" + "\t" + "150" + '\t' + "78" + '\t' + "100" + '\t' + "70" + '\t' + "50";
       
        string strValue = getValue();
        //添加一个series
        objChart.SeriesCollection.Add(0);        //给定series的名字
        objChart.SeriesCollection[0].SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimSeriesNames,
        +(int)Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral, strSeriesName);        //给定分类
        objChart.SeriesCollection[0].SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimCategories,
        +(int)Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral, strCategory);        //给定值
        objChart.SeriesCollection[0].SetData
        (Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimValues,
        (int)Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral, strValue);        //饼状图显示百分比
        if (chartType == "饼图")
        {
            ChDataLabels mytb = objChart.SeriesCollection[0].DataLabelsCollection.Add();
           
            mytb.HasValue = true;
        }
        //输出成GIF文件.
        string strAbsolutePath = (Server.MapPath(".")) + "\\test.gif";
        objCSpace.ExportPicture(strAbsolutePath, "GIF", 600, 350);        //创建GIF文件的相对路径.
        string strRelativePath = "./test.gif";        //把图片添加到placeholder.
        //string strImageTag = "<IMG SRC='" + strRelativePath + "'/>";
        //ChartHolder.Controls.Add(new LiteralControl(strImageTag));
        return strRelativePath;    }    private string getValue()
    {
        SalesDAL sd = new SalesDAL();
        List<Sales> list= sd.getLastSales();
        
        string content="";
        foreach (Sales sales in list)
        {
            content = sales.Yiyue.ToString().Trim() + "\t" + sales.Eryue.ToString().Trim() + "\t"+sales.Sanyue.ToString().Trim()+"\t"+sales.Siyue.Trim()+"\t"+sales.Wuyue.Trim()+"\t"+sales.Liuyue.Trim()+"\t"+sales.Qiyue.Trim()+"\t"+sales.Bayue.Trim()+"\t"+sales.Jiuyue.Trim()+"\t"+sales.Shiyue.Trim()+"\t"+sales.Shiyiyue.Trim()+"\t"+sales.Shieryue.Trim()+"\t";
        }
        return content;
    }
    [AjaxPro.AjaxMethod]
    protected void Timer1_Tick(object sender, EventArgs e)
    {
        this.Image1.ImageUrl = null;
        (this.FindControl("Image1") as Image).ImageUrl = getNewPic(this.DropDownList1.SelectedValue.ToString());
        //this.Page_Load(sender, e);
        
    }    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {        string chartType = this.DropDownList1.SelectedValue.ToString();
        //(this.FindControl("Image1") as Image).ImageUrl = getNewPic(chartType);
        this.Image1.ImageUrl = getNewPic(chartType);
    }
}

解决方案 »

  1.   

    定时刷新
    图使用?new Date,Math.random()
      

  2.   

    没看到你AJAX传送URL,应该是每次发送的URL相同,没有处理。URL 后面加上随机字符进行区分
      

  3.   

    我用的是ajax控件实现的,以前做系统当前时间都是这样搞的啊,现在想用ajax来定时刷新页面上的一个图形,这个图形是后台生成实现的,就是不能刷新这图图片。我把ajax控件删除后,这个图片可以刷新。在说一句:这图图片是一个实时监控的系统的图片,数据是在sql 2000里面取出来的,希望大家帮下忙。小女子谢了
      

  4.   

    哪位仁兄能给我个实时监控数据库数据的 在web上面显示的曲线图,柱状图,或者其他的表现形式的demo都可以,让我研究下,叩谢
      

  5.   

    Response.Write("<meta content='请教Asp批量录入产品编号 问题 Web 开发 ASP' name='Keywords'/>");
      

  6.   

    if (!IsPostBack)
      需要加这句?不回发,已经不刷新了