gpt4 book ai didi

javascript - 将 Json 数据加载到 jqPlot 中

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:22:26 24 4
gpt4 key购买 nike

<分区>

我对 JSON 和 jqPlot 有疑问。

jQuery 脚本:

var line = [ ];
$(function(){
$.getJSON('bin/gielda.php', function(data) {
$.each(data, function (index, value) {
line.push(["'"+data[index].data+"'",data[index].kurs_odn]);
});
console.log(line);
});
$.jqplot('chartdiv', [line], {
title :' Giełda',
axes : {
xaxis : {
renderer : $.jqplot.DateAxisRenderer
}
},
series : [{
lineWidth : 4,
markerOptions : {
style : 'square'
}
}]
});
});

来自 gielda.php 的 php:

$pdo = new PDO('mysql:host=localhost;dbname=gielda', 'root', '');
$pdo -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = $pdo -> prepare("SELECT data,kurs_odn FROM template WHERE nazwa=?");
$sql -> execute(array("ASSECOPOL"));
$gielda = $sql->fetchAll(PDO::FETCH_ASSOC);
echo json_encode($gielda);

php 文件的结果是这样的:

[{"data":"2010-08-19","kurs_odn":"55.75"},{"data":"2010-08-19","kurs_odn":"55.75"},{"data":"2010-08-19","kurs_odn":"55.75"},{"data":"2010-08-20","kurs_odn":"56.2"},{"data":"2010-08-20","kurs_odn":"56.2"},{"data":"2010-08-20","kurs_odn":"56.2"}]

来自可变行的 Console.log:

[["'2010-08-19'", "55.75"], ["'2010-08-19'", "55.75"], ["'2010-08-19'", "55.75"], ["'2010-08-20'", "56.2"], ["'2010-08-20'", "56.2"], ["'2010-08-20'", "56.2"]]

和错误:未捕获的异常:[object Object]

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com