1
我與jqplot的工作,我已經繪製的是來自數組PHP中的數據,但是當我試圖從JavaScript來繪製不工作攜帶一個PHP數組javascript和情節witjh jqplot
這是PHP代碼:
$array= array();
$array[] = 34.890;
$array[] = 25.090;
現在代碼吸收水分:
<script>
$(function() {
var array = new Array();
<?php
for($i=0; $i<count($array); $i++){
echo "\narray[$i] = '$array[$i]';";
}
?>
graficar( array );
});
</script>
功能graficar是:
function graficar(array)
{
var plot2 = $.jqplot('lienzo',
[
array
],
{
seriesDefaults: {
renderer: $.jqplot.BarRenderer,
// Show point labels to the right ('e'ast) of each bar.
// edgeTolerance of -15 allows labels flow outside the grid
// up to 15 pixels. If they flow out more than that, they
// will be hidden.
pointLabels: {show: true, location: 'e', edgeTolerance: -15},
// Rotate the bar shadow as if bar is lit from top right.
shadowAngle: 135,
// Here's where we tell the chart it is oriented horizontally.
rendererOptions: {
barDirection: 'horizontal',
barWidth:18
}
},
axes: {
yaxis: {
renderer: $.jqplot.CategoryAxisRenderer
}
}
}
);
}
我得到的錯誤是:
TypeError: this[r]._ticks[0] is undefined
[Break On This Error]
...{href:function(a){return a.getAttribute("href")},type:function(a){return a.getAt...
的圖表顯示:
如何解決我的麻煩?
坦克。
與PHP和JS中parseJson(jQuery的)json_encode :-) – 2013-03-22 16:10:43
也試試,智者可以讓你通過PHP數組到HTML頁面,然後你可以調用與JavaScript – 2013-03-22 16:20:39
這些陣列作爲KA_lin說使用json_encode在PHP使你的數組可以通過JavaScript來理解。但是,不需要在Javascript中使用parseJson,Jqplot可以處理它 – AnthonyLeGovic 2013-03-22 16:49:57