Kontribusi PHP Code For iLearning Media Business Intelligence 3

Setelah mendapatkan hasil berupa text yang sudah memiliki rasa BI pada Cermi sebelumnya. Saatnya untuk pembuatan chart untuk mempercantik tampilan dashboard.

Dalam pembuatan chart ini, butuh tambahan tool, maka dipilihlah Highcharts sebagai tambahannya. Kemudian untuk bisa dijalankan dalam iMe dibutuhkan beberapa script dalam PHP Code yang akan terhubung dengan highcharts.

Adapun PHP Code scriptnya adalah

 

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″>
<title>Dashboard</title>

<script type=”text/javascript” src=”http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js”></script>
<style type=”text/css”>
${demo.css}
</style>

</head>
<body>

<script src=”https://code.highcharts.com/highcharts.js”></script>
<script src=”https://code.highcharts.com/highcharts-3d.js”></script>
<script src=”https://code.highcharts.com/modules/exporting.js”></script>

 

Kemudian baru menggabungkan data dengan chart yang akan dipilih, untuk yang pertama sesuai dengan kriteria pada Cermi sebelumnya yaitu penulis artikel terbanyak, dan di sini akan dibatasi sampai 10 saja

Adapun PHP Code scriptnya adalah

 

<?php

//”include kedalam file koneksi WP, mungkin didalam iMe sama filenya sepert ini”
include “wp-config.php”;

//”Sintak Koneksi mysql”
$conn = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD ) or die (“tidak bisa connect ke database: ” . mysql_error());
mysql_select_db (DB_NAME) or die (“tidak bisa pilih database: ” . mysql_error());

//Situs yang akan dijalankan
$site = “$_SERVER[HTTP_HOST]”;

//”Query” (di sesuaikan dengan kebutuhan)
$sql = “SELECT blog_id
FROM wp_blogs
WHERE domain =’$site'”;
$query=mysql_query($sql);
$r = mysql_fetch_array($query);

$sql2 = “SELECT wp_users.user_login, wp_users.display_name,
COUNT(wp_$r[0]_posts.post_content) as Post,
SUM(wp_$r[0]_posts.comment_count) as Comment,
wp_usermeta.meta_value
FROM wp_$r[0]_posts LEFT JOIN wp_users
ON wp_$r[0]_posts.post_author = wp_users.ID
INNER JOIN wp_usermeta
ON wp_users.ID = wp_usermeta.user_id
WHERE wp_usermeta.meta_key = ‘wp_$r[0]_capabilities’ AND
wp_usermeta.meta_value LIKE ‘%author%’ AND
wp_$r[0]_posts.post_status = ‘publish’
AND wp_$r[0]_posts.post_type = ‘post’
group by wp_users.display_name
ORDER BY Post DESC LIMIT 10″;
$query2=mysql_query($sql2);
?>

<script type=”text/javascript”>
$(function () {
// Set up the chart
var chart = new Highcharts.Chart({
chart: {
renderTo: ‘containerpost’,
type: ‘column’,
options3d: {
enabled: true,
alpha: 0,
beta: 0,
depth: 100,
viewDistance: 25
}
},
title: {
text: ’10 Penulis Artikel Terbanyak’
},
plotOptions: {
column: {
depth: 25
}
},
xAxis: {
categories: [
‘Penulis’
]
},
yAxis: {
min: 0,
title: {
text: ‘Jumlah’
}
},
series: [
<?php
while($r2=mysql_fetch_array($query2)){
echo “{ name: ‘”.$r2[“1”].”‘,data: [“.$r2[“2″].”]},”;
}
?>
]
});

function showValues() {
$(‘#alpha-value’).html(chart.options.chart.options3d.alpha);
$(‘#beta-value’).html(chart.options.chart.options3d.beta);
$(‘#depth-value’).html(chart.options.chart.options3d.depth);
}

// Activate the sliders
$(‘#sliderspost input’).on(‘input change’, function () {
chart.options.chart.options3d[this.id] = this.value;
showValues();
chart.redraw(false);
});

showValues();
});
</script>
<style>
#containerpost, #sliderspost {
min-width: 310px;
max-width: 800px;
margin: 0 auto;
}
#containerpost {
height: 400px;
}
</style>

<div id=”containerpost”></div>
<div id=”sliderspost”>
<table>
<tr>
<td>Alpha Angle</td>
<td><input id=”alpha” type=”range” min=”0″ max=”45″ value=”0″/> <span id=”alpha-value” class=”value”></span></td>
</tr>
<tr>
<td>Beta Angle</td>
<td><input id=”beta” type=”range” min=”-45″ max=”45″ value=”0″/> <span id=”beta-value” class=”value”></span></td>
</tr>
<tr>
<td>Depth</td>
<td><input id=”depth” type=”range” min=”20″ max=”100″ value=”100″/> <span id=”depth-value” class=”value”></span></td>
</tr>
</table>
</div>

 

Kemudian kriteria 10 komentator terbanyak

Adapun PHP Code scriptnya adalah

 

<?php

//”include kedalam file koneksi WP, mungkin didalam iMe sama filenya sepert ini”
include “wp-config.php”;

//”Sintak Koneksi mysql”
$conn = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD ) or die (“tidak bisa connect ke database: ” . mysql_error());
mysql_select_db (DB_NAME) or die (“tidak bisa pilih database: ” . mysql_error());

//Situs yang akan dijalankan
$site = “$_SERVER[HTTP_HOST]”;

//”Query” (di sesuaikan dengan kebutuhan)
$sql = “SELECT blog_id
FROM wp_blogs
WHERE domain =’$site'”;
$query=mysql_query($sql);
$r = mysql_fetch_array($query);

$sql2 = “SELECT wp_users.user_login, wp_users.display_name,
COUNT(wp_$r[0]_comments.comment_content) as Jumlah,
wp_usermeta.meta_value
FROM wp_$r[0]_comments LEFT JOIN wp_users ON wp_$r[0]_comments.user_id = wp_users.ID
INNER JOIN wp_usermeta
ON wp_users.ID = wp_usermeta.user_id
WHERE wp_usermeta.meta_key = ‘wp_$r[0]_capabilities’ AND
wp_usermeta.meta_value LIKE ‘%author%’ AND
wp_$r[0]_comments.comment_approved = ‘1’
group by wp_users.display_name ORDER BY Jumlah DESC LIMIT 10″;
$query2=mysql_query($sql2);

?>
<script type=”text/javascript”>
$(function () {
$(‘#containercom’).highcharts({
chart: {
type: ‘pie’,
options3d: {
enabled: true,
alpha: 45
}
},
title: {
text: ’10 Komentator Terbanyak’
},
plotOptions: {
pie: {
innerSize: 100,
depth: 45
}
},
series: [{ name: ‘Jumlah’,
data: [
<?php
while($r2=mysql_fetch_array($query2)){
echo “[‘”.$r2[“1″].”‘,”.$r2[“2″].”],”;
}
?>
] }
]
});
});
</script>
<div id=”containercom” style=”height: 400px”></div>

 

Selanjutnya yang terakhir adalah 10 Artikel dengan komentar terbanyak

Adapun PHP Code scriptnya adalah

 

<?php

//”include kedalam file koneksi WP, mungkin didalam iMe sama filenya sepert ini”
include “wp-config.php”;

//”Sintak Koneksi mysql”
$conn = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD ) or die (“tidak bisa connect ke database: ” . mysql_error());
mysql_select_db (DB_NAME) or die (“tidak bisa pilih database: ” . mysql_error());

//Situs yang akan dijalankan
$site = “$_SERVER[HTTP_HOST]”;

//”Query” (di sesuaikan dengan kebutuhan)
$sql = “SELECT blog_id
FROM wp_blogs
WHERE domain =’$site'”;
$query=mysql_query($sql);
$r = mysql_fetch_array($query);

$sql2 = “SELECT wp_users.user_login, wp_$r[0]_posts.post_title, wp_users.display_name,
COUNT(wp_$r[0]_comments.comment_content) as Jumlah,
wp_usermeta.meta_value
FROM wp_$r[0]_comments LEFT JOIN wp_$r[0]_posts
ON wp_$r[0]_comments.comment_post_id = wp_$r[0]_posts.ID
INNER JOIN wp_users ON wp_$r[0]_posts.post_author = wp_users.ID
INNER JOIN wp_usermeta
ON wp_users.ID = wp_usermeta.user_id
WHERE wp_usermeta.meta_key = ‘wp_$r[0]_capabilities’ AND
wp_usermeta.meta_value LIKE ‘%author%’ AND
wp_$r[0]_comments.comment_approved = ‘1’
group by wp_$r[0]_posts.ID
ORDER BY Jumlah DESC limit 10″;
$query2=mysql_query($sql2);

?>
<script type=”text/javascript”>
$(function () {
$(‘#containertp’).highcharts({
chart: {
type: ‘pie’,
options3d: {
enabled: true,
alpha: 45,
beta: 0
}
},
title: {
text: ’10 Artikel dengan Komentar Terbanyak’
},
tooltip: {
pointFormat: ‘{series.name}: <b>{point.y:f}</b>’
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: ‘pointer’,
depth: 35,
dataLabels: {
enabled: true,
format: ‘{point.name}’
}
}
},
series: [{
type: ‘pie’,
name: ‘Jumlah’,
data: [
<?php
while($r2=mysql_fetch_array($query2)){
echo “[‘”.$r2[“2″].”‘,”.$r2[“3″].”],”;
}
?>

]
}]
});
});
</script>
<div id=”containertp” style=”height: 400px”></div>

 

Demikian progress yang sudah dilakukan dalam iMe Class SMK AL Fattah (ALFiL Class)

52 Total Views 1 Views Today
Views All Time
Views All Time
48
Views Today
Views Today
1

Article written by

never give up

3 Responses

Leave a Reply

You must be logged in to post a comment.