[英]Graph not displaying Java-Script
<script>
// Data Values for the chart.
var newArray = new Array();
var newArray = <?php echo json_encode($values); ?>;
// Bar Chart.
if($("#chart-3").length > 0)
{
var data = [];
for( var i = 0; i < newArray.length; i++)
{
data[i] = { data: newArray[i]}; // this causing problem.
console.log(data[i]);
}
$.plot($("#chart-3"), data,
{
series:
{
pie: { show: true }
},
legend: { show: false }
});
}
</script>
If i put 4
in place of newArray[i]
then graph is displaying values. 如果我用
4
代替newArray[i]
那么图形将显示值。 I used the console.log() to check what values i am getting in newArray and what i am getting is: 我使用console.log()来检查我在newArray中得到的值以及我得到的是:
console.log() output: console.log()输出:
Object {data: "4"}
Object {data: "2"}
To ensure the numeric value is indeed numeric and not a string, you could do this: 为了确保数值确实是数字而不是字符串,您可以这样做:
data[i] = { data: parseInt(newArray[i])};
or use parseFloat
if that is more appropriate. 或使用
parseFloat
如果更合适)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.