我试图让 flotr2 图表在我的 Phonegap 应用程序中工作。我可以让他们的示例图(http://www.humblesoftware.com/flotr2/documentation#usage)在 AVD 上运行,但是如果我尝试在我的实际应用程序中使用它,它会给我错误 Uncaught The target container must在 file:///android_asset/www/flotr2.min.js:27 上可见 我将如何解决这个问题?
与 fltr2 相关的代码:
//Flotr2 style contained in head below other styles
<style type="text/css">
body {
margin: 0px;
padding: 0px;
}
#container {
width : 600px;
height: 384px;
margin: 8px auto;
}
</style>
//Accidentally changing </style> to </script> causes the graph to display
//but everything else is wrong, as can be expected
和:
//Page meant to contain graph; in body
<!-- Graphs -->
<div data-role="page" data-theme="a" id="page21">
<div data-theme="a" data-role="header">
<h3>
Graphs
</h3>
<a data-role="button" data-direction="reverse" data-transition="slide" href="#page15" data-icon="arrow-l" data-iconpos="left" class="ui-btn-left">
Back
</a>
</div>
<div data-role="content" style="padding: 15px">
<div id="container"></div>
<script type="text/javascript" src="flotr2.min.js"></script>
<script type="text/javascript">
(function () {
var
container = document.getElementById('container'),
start = (new Date).getTime(),
data, graph, offset, i;
// Draw a sine curve at time t
function animate (t) {
data = [];
offset = 2 * Math.PI * (t - start) / 10000;
// Sample the sine function
for (i = 0; i < 4 * Math.PI; i += 0.2) {
data.push([i, Math.sin(i - offset)]);
}
// Draw Graph
graph = Flotr.draw(container, [ data ], {
yaxis : {
max : 2,
min : -2
}
});
// Animate
setTimeout(function () {
animate((new Date).getTime());
}, 50);
}
animate(start);
})();
</script>
</div>
</div>