Not too long ago, I asked this question. However, I am still encountering errors and feeling confused about how to resolve them.
I have some code that I want to modify as follows:
var data = google.visualization.arrayToDataTable([
['Location', 'Parent', 'Size', 'Color'],
['Jawa', null, 0, 0],
['Jawa Tengah', 'Jawa', 0, 0],
['Jawa Timur', 'Jawa', 0, 0],
['Jawa Barat', 'Jawa', 0, 0],
['SAL01', 'Jawa Barat', 89, 50],
['SAL02', 'Jawa Tengah', 77, 40],
['SAL03', 'Jawa Tengah', 71, 28]
]);
Here is the snippet of my code:
function drawChart(){
var dataFromPHP = <?php echo file_get_contents('clientdata.json'); ?>;
$dataFromPHP = file_get_contents('clientdata.json');
$json = json_decode($dataFromPHP, TRUE);
// Console.log(dump_dataFromPHP);
$provinsi = 'SELECT provinsi , LEFT(provinsi, 4) AS lala FROM data_client';
$query = 'SELECT provinsi ,kode_sales, gaji, count(kode_sales) AS T_nasabah FROM data_client GROUP BY kode_sales';
$exec = mysqli_query($con,$query);
$execProv = mysqli_query($con,$provinsi);
var data = google.visualization.arrayToDataTable([
['Location', 'Parent' , 'Size', 'Color'],
echo "['".$row['lala']."', null, 0, 0],";
while($row = mysqli_fetch_array($execProv)){
echo "['".$row['provinsi']."','".$row['lala']."',0,0],";
}
while($row = mysqli_fetch_array($exec)){
echo "['".$row['kode_sales']."','".$row['provinsi']."',".$row['gaji'].",".$row['T_nasabah']."],";
}];
This is the content of my clientdata.json file:
[
{
"kode_client": "CLI01",
"nama": "Edo",
"tanggal_lahir": "01\/05\/1967",
"alamat": "Nusa Hijau",
"telp": "085634234",
"produk": "Titanium",
"gaji": "5000000",
"cabang": "Bandung",
"provinsi": "Jawa Barat",
"kode_sales": "SAL01"
},
{
"kode_client": "CLI02",
"nama": "Santoso Imam",
"tanggal_lahir": "15\/12\/1979",
"alamat": "Padasuka",
"telp": "08513087645",
"produk": "Investra Link",
"gaji": "4500000",
"cabang": "Cimahi",
"provinsi": "Jawa Tengah",
"kode_sales": "SAL02"
},
{
"kode_client": "CLI03",
"nama": "Mukidi",
"tanggal_lahir": "01\/01\/1991",
"alamat": "Mujihat",
"telp": "085213123",
"produk": "Titanium",
"gaji": "12500000",
"cabang": "Bandung",
"provinsi": "Jawa Tengah",
"kode_sales": "SAL03"
}
]
I need to format these values for my Treemap chart using Google Chart. Your help is greatly appreciated. Thank you in advance :')