0

我依靠 jqplot 的 jqplotToImageStr({}) 函数从我的图表中生成一个 png 作为 base64 字符串。然后我将 base64 表示发送到服务器以完成我的工作。问题是当浏览器(<= IE 8)不支持画布时,jqplotToImageStr({}) 返回 null。即使在不知道画布的浏览器中,有没有一种方法可以成功使用 jqplotToImageStr({}) ?

4

2 回答 2

0

根据我的经验,这是不可能的。我们在服务器端检查字符串输入,如果输入为空,则向用户返回一条消息。

于 2013-10-07T11:59:43.247 回答
0

试试下面的 javascript(从 jqplot 示例复制)。将其附加到页面的末尾。

<script>
    $(document).ready(function(){if(!$.jqplot._noCodeBlock){$("script.code").each(function(c){if($("pre.code").eq(c).length){$("pre.code").eq(c).text($(this).html())}else{var d=$('<pre class="code prettyprint brush: js"></pre>');$("div.jqplot-target").eq(c).after(d);d.text($(this).html());d=null}});$("script.common").each(function(c){$("pre.common").eq(c).text($(this).html())});var b="";if($("script.include, link.include").length>0){if($("pre.include").length==0){var a=['<div class="code prettyprint include">','<p class="text">The charts on this page depend on the following files:</p>','<pre class="include prettyprint brush: html gutter: false"></pre>',"</div>"];a=$(a.join("\n"));$("div.example-content").append(a);a=null}$("script.include").each(function(c){if(b!==""){b+="\n"}b+='<script type="text/javascript" src="'+$(this).attr("src")+'"><\/script>'});$("link.include").each(function(c){if(b!==""){b+="\n"}b+='<link rel="stylesheet" type="text/css" hrf="'+$(this).attr("href")+'" />'});$("pre.include").text(b)}else{$("pre.include").remove();$("div.include").remove()}}if(!$.jqplot.use_excanvas){$("div.jqplot-target").each(function(){var d=$(document.createElement("div"));var g=$(document.createElement("div"));var f=$(document.createElement("div"));d.append(g);d.append(f);d.addClass("jqplot-image-container");g.addClass("jqplot-image-container-header");f.addClass("jqplot-image-container-content");g.html("Right Click to Save Image As...");var e=$(document.createElement("a"));e.addClass("jqplot-image-container-close");e.html("Close");e.attr("href","#");e.click(function(){$(this).parents("div.jqplot-image-container").hide(500)});g.append(e);$(this).after(d);d.hide();d=g=f=e=null;if(!$.jqplot._noToImageButton){var c=$(document.createElement("button"));c.text("View Plot Image");c.addClass("jqplot-image-button");c.bind("click",{chart:$(this)},function(h){var j=h.data.chart.jqplotToImageElem();var i=$(this).nextAll("div.jqplot-image-container").first();i.children("div.jqplot-image-container-content").empty();i.children("div.jqplot-image-container-content").append(j);i.show(500);i=null});$(this).after(c);c.after("<br />");c=null}})}$(document).unload(function(){$("*").unbind()})});
</script>
于 2013-10-16T18:14:27.183 回答