SkySpeedAvatar border
TS
SkySpeed
Highchart dengan data dari JSON
oke. jadi gini gan. ane berusaha buat Highchart yang datanya dari JSON. pertama2 ane buat php yang buat nge generate JSONnya. kodenya seperti ini.

Code:

<?php
$mysqli = new mysqli("localhost", "root", "", "test");

$resu = array();
$measurement = $_POST["choosenmeasurement"];

for($i = 0; $i < count($_POST["choosenbusid"]); $i++)
{
$busid = $_POST["choosenbusid"][$i];
$clusid = $_POST["choosenclusterid"][$i];

$fieldname = ''.$measurement.'_BUSID_'.$busid.'_CLUSTERID_'.$clusid;

$sql= "SELECT unix_timestamp, $measurement as $fieldname FROM `get` WHERE bus_id = $busid and cluster_id = $clusid";
$sth = $mysqli->query($sql);

$out = array();
$out['name'] = $fieldname;
while ($rr = $sth->fetch_row()) {
$out['data'][] = array($rr[0],$rr[1]);
}
array_push($resu,$out);
}
$jsonresult = json_encode($resu, JSON_NUMERIC_CHECK);

print $jsonresult;
?>


itu nanti bisa nge generate JSON nya.

lalu saya buat highchartsnya dengan kode seperti ini.

Code:


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Highcharts Example</title>

[removed][removed]
[removed]
$(function () {
var chart;

$(document).ready(function() {
$.getJSON("test.php", function(json) {
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'line',
marginRight: 130,
marginBottom: 25
},
title: {
text: '',
x: -20 //center
},
subtitle: {
text: '',
x: -20
},
yAxis: {
title: {
text: ''
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
formatter: function() {
return '<b>'+ this.series.name +'</b><br/>'+
this.x +': '+ this.y;
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -10,
y: 100,
borderWidth: 0
},
series: json
});
});

});

});
[removed]
</head>
<body>
[removed][removed]
[removed][removed]

<div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div>

</body>
</html>


dan abis itu dia gamao jalan gan. tapi kalo ane buat kya gini

Code:

$(document).ready(function() {
$.getJSON("new.txt", function(json)


yang mana file "new.txt" tersebut saya telah isi dengan file JSON dari php file yang nge generate JSON dia mao jalan gan.

mohon pencerahannya. ane bingung. thanks before gan.
Diubah oleh SkySpeed 08-05-2014 14:13
0
900
1
GuestAvatar border
Guest
Tulis komentar menarik atau mention replykgpt untuk ngobrol seru
Urutan
Terbaru
Terlama
GuestAvatar border
Guest
Tulis komentar menarik atau mention replykgpt untuk ngobrol seru
Komunitas Pilihan