ASP.Net 图表 - 在 IE 7 上通过 jQuery 获取导致图像无法加载

发布于 2024-08-08 22:14:09 字数 1980 浏览 7 评论 0原文

我正在使用 ASP.Net 图表控件 和 ASP.Net MVC。

我试图在页面上显示一个图表,用户可以更改与该图表关联的各种数据,然后按下一个按钮,该按钮将执行 POST 操作,然后返回新渲染的图表。这是通过 jQuery 刷新的,它加载包含图表的部分视图。

我遇到的问题是,在 IE 7 中我得到图像无法找到图标。奇怪的是它在 Firefox 中运行得很好!

更新图表的过程:

  • 在 POST 中发送新参数
  • 应用程序更改了图表对象上的参数
  • 控制器将图表对象发送到部分视图,部分视图将其呈现为 jQuery 控件,
  • 然后加载到此部分视图中。在 IE 7 中,我得到图像未找到图标。

以下是部分视图中用于呈现图表对象的代码:

if (Model.Chart != null)
        {
            Model.Chart.Page = this.Page;
            System.Web.UI.DataVisualization.Charting.Chart Chart1 = Model.Chart;
            using (HtmlTextWriter writer = new HtmlTextWriter(this.Response.Output))
            {
                try
                {

                    Chart1.ImageType = System.Web.UI.DataVisualization.Charting.ChartImageType.Jpeg;
                    Chart1.RenderControl(writer);
                }
                catch (Exception ex)
                {
                    writer.WriteEncodedText(ex.Message);
                }
            }
        }

干杯!

加载这些图表的 jQuery 如下:

function PostWidgetDataOverride(ChartID) {
    $.ajax({
        url: "/Home/GetChart",
        type: "POST",
        dataType: "HTML",
        data: { ChartID: ChartID, SeriesID: $('.SeriesID').val(), ParameterDefaults: $('.parameterDefault').serialize(), Time: getTimeStamp() },
        success: UpdateChart
    });
}

function UpdateChart(ChartContent) {
   $("#widgetConfig").dialog("close");
   var existingChart = CheckIfWidgetIsOnPage($(ChartContent).attr("id"))

   if (existingChart !== undefined) {
       existingChart.fadeOut("slow", function() { existingChart.replaceWith(ChartContent); }).fadeIn("slow");
   }
  else {
       $(ChartContent).appendTo($("#dashboardArea")).fadeIn("slow");
   }
}

I am using the ASP.Net Charting Controls and ASP.Net MVC.

I am trying to have a chart displayed on a page, the user can change various data associated with this chart and then press a button which will perform a POST operation and then return a newly rendered chart. This is refreshed via jQuery which loads a partial view containing the chart.

The problem I am having is that in IE 7 I get the image could not be found icon. Bizarrely it works fine in Firefox!

The process of updating chart:

  • Send new parameters in a POST
  • Application changed parameters on the chart object
  • Controller sends Chart Object to Partial View which renders it like a control
  • jQuery then loads in this partial view. In IE 7 i get the image not found icon.

Here is the code used in the Partial View to render the Chart Object:

if (Model.Chart != null)
        {
            Model.Chart.Page = this.Page;
            System.Web.UI.DataVisualization.Charting.Chart Chart1 = Model.Chart;
            using (HtmlTextWriter writer = new HtmlTextWriter(this.Response.Output))
            {
                try
                {

                    Chart1.ImageType = System.Web.UI.DataVisualization.Charting.ChartImageType.Jpeg;
                    Chart1.RenderControl(writer);
                }
                catch (Exception ex)
                {
                    writer.WriteEncodedText(ex.Message);
                }
            }
        }

Cheers!

The jQuery which loads these charts is as follows:

function PostWidgetDataOverride(ChartID) {
    $.ajax({
        url: "/Home/GetChart",
        type: "POST",
        dataType: "HTML",
        data: { ChartID: ChartID, SeriesID: $('.SeriesID').val(), ParameterDefaults: $('.parameterDefault').serialize(), Time: getTimeStamp() },
        success: UpdateChart
    });
}

function UpdateChart(ChartContent) {
   $("#widgetConfig").dialog("close");
   var existingChart = CheckIfWidgetIsOnPage($(ChartContent).attr("id"))

   if (existingChart !== undefined) {
       existingChart.fadeOut("slow", function() { existingChart.replaceWith(ChartContent); }).fadeIn("slow");
   }
  else {
       $(ChartContent).appendTo($("#dashboardArea")).fadeIn("slow");
   }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

箜明 2024-08-15 22:14:09

我认为问题在于你如何获得图像。从您发布的代码来看,您似乎是通过 ajax 下载获取实际的图像数据,然后将新的图像数据插入到 DOM 中。这可能适用于 Firefox,但不适用于 IE(PS 也从未尝试过)。无论如何,假设 IE 不喜欢这样,最好通过图像元素的源属性将图像指向图像处理程序。当您需要更改图像时,只需更改发送到处理程序的 url 中的参数,当此更改时,IE 和 Firefox 都会发出新图像的请求。例如:

HTML :

<img src="./chart.aspx?SeriesId=456&ChartId=123&Time=20091021155300" id="chart" />

当您需要更新图表时,来自 jQuery 的

function UpdateChart(chartId, seriesId, time){
  $("#chart").attr("src","./chart.aspx?SeriesId="+seriesId+"&ChartId="+chartId+"&Time="+time);
}

I think the problem is how you get the image. From the code you posted it looks like you are getting the actual image data via a ajax download and then inserting the new image data into the DOM. This might work for Firefox, but not for IE (P.S never tried either). Anyway assuming that IE does not like this it would be better to point the image at an image handler via the source attribute of the image element. When you need to change the image just change the parameters in the url sent to handler, when this changes IE and Firefox will both make a request for the new image. For example:

The HTML

<img src="./chart.aspx?SeriesId=456&ChartId=123&Time=20091021155300" id="chart" />

The from jQuery when you need to update the chart:

function UpdateChart(chartId, seriesId, time){
  $("#chart").attr("src","./chart.aspx?SeriesId="+seriesId+"&ChartId="+chartId+"&Time="+time);
}
何其悲哀 2024-08-15 22:14:09

您可以编写一个服务来清理 x 天前的图像,或者您可以使用 #SEQ(maxFiles, 分钟) 来设置过期时间,但这在命名方面并不灵活。

you can write a service to clean up images which are x days old or you can use #SEQ(maxFiles,minutes) to set the expiration but that is not really flexible with naming.

流心雨 2024-08-15 22:14:09

使其工作

Chart1.ImageStorageMode = System.Web.UI.DataVisualization.Charting.ImageStorageMode.UseImageLocation

我通过将 ImageStorageMode 更改为:但现在它挂在文件夹中来 。我不想让文件夹塞满图像......

I got it working by changing ImageStorageMode to:

Chart1.ImageStorageMode = System.Web.UI.DataVisualization.Charting.ImageStorageMode.UseImageLocation

but now it hangs around in a folder. I don't want a folder clogging up with images...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文