0
に3つのフィールドを返す方法を次のよう:私はアヤックスこの情報の検索を持っている私のHTMLで返すPHPで私がサービスを持っているJSONと人気チャート
[[1,"16846"],[2,"16858"],[3,"16923"],[4,"16891"]]
。
$.ajax({
type: 'POST',
url: 'getDadosGrafico.php',
dataType: 'json', // use this
success: function(data) {
var dados = data;
グラフには3つのレコードが必要ですが、すでにデータベースに3つの列があります。 どのように私はアヤックスはあなたがそれぞれ、3つのプロパティを持つオブジェクトを返す必要が3列
私のコードのPHP
$stmt = $con->prepare($sql);
$stmt->execute();
$users = $stmt->fetchAll();
$cont=1;
$dataset1 = array();
foreach ($users as $row) {
$data = $row['data_reenvio'];
$data_formatada=date('d/m/Y',strtotime($data));
$dataset1[] = array($cont , $row['total_sucesso'], $row['total_falha'], $row['total']);
$cont++;
}
print (json_encode($dataset1));
マイコードHTML
$.ajax({
type: 'POST',
url: 'getDadosGrafico.php',
dataType: 'json', // use this
success: function(data) {
var dados = data;
// Graph Data ##############################################
var graphData = [{
// Visits
data: dados, //[ [6, 1300], [7, 1600], [8, 1900], [9, 2100], [10, 2500], [11, 2200], [12, 2000], [13, 1950], [14, 1900], [15, 2000] ],
color: '#71c73e'
}, {
// Returning Visits
data: [ [1, 15500], [2, 16000], [3, 16550], [4, 16000], [5, 16800], [6, 16900], [7, 16800], [8, 16850], [9, 16830], [10, 17000] ],
color: '#77b7c5',
points: {
radius: 4,
fillColor: '#77b7c5'
}
}, {
// Returning Visits
data: [ [1, 17500], [2, 17000], [3, 17550], [4, 18000], [5, 18800], [6, 18900], [7, 18800], [8, 18850], [9, 18830], [10, 17000] ],
color: '#77b7c5',
points: {
radius: 4,
fillColor: '#0007c5'
}
}
];
PHPでこれを行うには – Will
私は自分の答えをPHPの答えと考えて編集しました。 –
パーフェクト!ありがとうございました!!! – Will