Android Webview谷歌图表不起作用
我一直在互联网上搜索,寻找一种嵌入网络视图的解决方案,该视图显示带有谷歌图表的网页。到目前为止,我什么也没找到。我不想使用图像API,也不想构建html,因为我无法访问渲染图表所需的数据 有什么建议吗 堆栈跟踪:Android Webview谷歌图表不起作用,android,webview,google-visualization,Android,Webview,Google Visualization,我一直在互联网上搜索,寻找一种嵌入网络视图的解决方案,该视图显示带有谷歌图表的网页。到目前为止,我什么也没找到。我不想使用图像API,也不想构建html,因为我无法访问渲染图表所需的数据 有什么建议吗 堆栈跟踪: 09-29 12:26:34.158 29906-29906/xxxxxxxxxxxxxxx E/AndroidRuntime﹕ FATAL EXCEPTION: main java.lang.NullPointerException at x
09-29 12:26:34.158 29906-29906/xxxxxxxxxxxxxxx E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NullPointerException
at xxxxxxxxxxxxxxx.MMStatisticsActivity.onCreateView(MMStatisticsActivity.java:32)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:870)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1080)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:622)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1416)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:420)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4895)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
at dalvik.system.NativeStart.main(Native Method)
代码:
值得一提的是,我在一个片段中加载了WebView。我在WebView中显示了一个google图表,并没有发现那么困难 html文件的代码段:
//include google api js file
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
//a div for chart
<div id="my-chart">
</div>
希望能有帮助。您需要根据需要自定义图表选项。并参考启动它
编辑:
如果你有一个显示谷歌图表的URL,那么你只需要添加
myWebView.loadUrl(strLink);
在您的活动中。您的解决方案暗示我拥有渲染图形所需的数据,而我没有。我的问题是,这不是我想要的解决方案。总之,谢谢你的回答。@TompaLompa那么你需要的数据在哪里呢?在原生android中?你想在js?@TompaLompa中显示,你需要在你的网络视图中显示该网页吗?那么你不能使用
myWebView.loadUrl(strLink)代码>?strLink将成为你的网页url的位置?尝试过了,应用程序崩溃了我们可以给它动画吗?MMStatisticsActivity上的空指针。java:32。那条线是什么?另外,添加相关代码。第32行是什么?WebView浏览器=(WebView)视图.findViewById(R.id.schedule\u WebView);WebView id在那里。好的。。调试并查看view
是否为空。可能是充气时出错了。什么要点?问题解决了吗?
// In case there is no network
// the google jsapi is not loaded causing the screen to go white and break the application
// Check if google object is not null
if(typeof(google) !== 'undefined')
{
google.load('visualization', '1.0', {'packages':['corechart']});
}
//a separate function for drawing data. Just call it wherever you need to redraw the chart
function drawChart(chartData){
data = new google.visualization.DataTable();
data.addColumn('string', 'Col1');
data.addColumn('number', 'Col2');
for (var i = 0; i < 5; i++)
{
ideasChart.data.addRow("data1", "data2");
}
chart = new google.visualization.ComboChart(document.getElementById('my-chart'));
chart.draw(data, chartOptions);
}
//chartOptions to customize your chart, its text color, etc.
chartOptions = {
chartType:"ComboChart",
containerId:"visualization",
stackSeries: true,
isStacked : true,
backgroundColor: '#242424',
legend: 'none',
tooltip:{
trigger:'none'
},
enableInteractivity: false,
colors : ['#6DB1E2','#FDCB34'],
chartArea: {
backgroundColor: {
stroke: '#fff',
strokeWidth: 1
}
},
seriesDefaults: {
rendererOptions: {
barPadding: 0,
barMargin: 10
},
},
seriesType: "bars",
bar:
{
groupWidth:"80%"
},
viewWindowMode : {
max: 'pretty'
}
};
myWebView.loadUrl("file:///android_asset/www/index.html");
myWebView.loadUrl(strLink);