Android 浏览器中 Google 可视化条形图 API 出现错误
我正在使用 ASP.NET MVC3、Razor、jQuery Mobile
并使用一些 java 脚本
调用 Google Chart API
来绘制 Bar图表(可视化 API)。它在桌面浏览器上运行良好,但在 Android 浏览器中失败并出现奇怪的错误。
“无法读取 null 的属性“appendchild”。”
Java 脚本代码位于“Body”元素内。以下是代码:- 我尝试在没有母版页的情况下运行它,其中包含 jquery mobile script
文件,行为相同,因此 jquery mobile
不应该受到指责。
@model System.Collections.Generic.List<Insight.CloudWeb.ViewModels.KeyFigureViewModel>
@{
ViewBag.Title = "KeyFigures";
Layout = null;
}
google.load("visualization", "1", { packages: ["corechart","table"] });
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
@foreach (var obj in Model)
{
@: data.addColumn('number', '@obj.Description @obj.Value');
}
i = 0;
data.addRows(1);
@foreach (var obj in Model)
{
@: data.setCell(0, i, @obj.Value);
@: i = i +1;
}
var chartBar = new google.visualization.BarChart(document.getElementById('chart_div'));
chartBar.draw(data, { height: 340, width: 500, title: 'Key Figures', chartArea: {left: 2, top: 2}, colors:['blue','red','green','yellow','orange','purple'],legend: 'right' });
}
</script>
<div id='chart_div'>
</div>
<div id='table_div'>
</div>
I am using ASP.NET MVC3, Razor, jQuery Mobile
and having some java scripts
which calls Google Chart API
, to draw Bar Chart (Visualization API). It is working fine on Desktop browsers but failing with strange errors in Android Browsers.
"Cannot read property 'appendchild' of null."
Java script code is inside "Body" element. following is the code:-
I tried to run it without master page, which include jquery mobile script
files, same behavior, so jquery mobile
is not to blame.
@model System.Collections.Generic.List<Insight.CloudWeb.ViewModels.KeyFigureViewModel>
@{
ViewBag.Title = "KeyFigures";
Layout = null;
}
google.load("visualization", "1", { packages: ["corechart","table"] });
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
@foreach (var obj in Model)
{
@: data.addColumn('number', '@obj.Description @obj.Value');
}
i = 0;
data.addRows(1);
@foreach (var obj in Model)
{
@: data.setCell(0, i, @obj.Value);
@: i = i +1;
}
var chartBar = new google.visualization.BarChart(document.getElementById('chart_div'));
chartBar.draw(data, { height: 340, width: 500, title: 'Key Figures', chartArea: {left: 2, top: 2}, colors:['blue','red','green','yellow','orange','purple'],legend: 'right' });
}
</script>
<div id='chart_div'>
</div>
<div id='table_div'>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为内置 Android 浏览器不支持 SVG。 (这对我来说是令人震惊的消息)。
直到 2.4 Gingerbread Android 内置浏览器还不支持 SVG 图像,由 Google 可视化生成 SVG 图像。
SVG 支持从 HoneyComb 开始
http://googlesystem.blogspot.com/2011/02 /android-honeycombs-browser-supports-svg.html
直到 Gingerbread 不支持 SVG 图像:-
http://www.mobilexweb.com/blog/android-2 -3-gingerbread-the-browser
发现 Opera 移动浏览器在 Android 手机上以非常好的方式支持 SVG,暂时向我的客户推荐同样的方式。
This is because Built-in Android Browsers do not support SVG. (It was shocking news for me).
Till 2.4 Gingerbread Android built-in browser has no support for SVG images, and Google visualization generated SVG images.
SVG support started from HoneyComb
http://googlesystem.blogspot.com/2011/02/android-honeycombs-browser-supports-svg.html
Till Gingerbread there is no support for SVG images:-
http://www.mobilexweb.com/blog/android-2-3-gingerbread-the-browser
found that opera mobile browser support SVG in very nice way on android phones, going to recommend my customers same for time being.