Berikut tahap - tahap dalam membuat diagram chart data penduduk dengan php mysql.
pertama buat nama databasenya db_chart - selanjutnya import sql berikut/
CREATE TABLE IF NOT EXISTS `datapenduduk` (
`provinsi` varchar(50) NOT NULL,
`jumlah` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Dumping data for table `datapenduduk`
--
INSERT INTO `datapenduduk` (`provinsi`, `jumlah`) VALUES
('Aceh', 3930905),
('Jawa', 11649655),
('Kalimantan', 4957627),
('Maluku', 2413846),
('Papua', 4248934);
sekarang buat file kode (script) phpnya untuk mengakses tabel sqlnya yang nanti akan di tampilkan dalam bentuk Diagram Chart<!DOCTYPE html>
<html>
<meta charset="UTF-8">
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<head>
<title>Grafik Penduduk Indonesia</title>
<script src="js/jquery-1.9.1.min.js" type="text/javascript"></script>
<script src="js/highcharts.js" type="text/javascript"></script>
<script src="js/exporting.js" type="text/javascript"></script>
<script type="text/javascript">
var chart1; // globally available
$(document).ready(function() {
chart1 = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'column'
},
title: {
text: 'Data Penduduk Provinsi Indonesia '
},
xAxis: {
categories: ['Provinsi']
},
yAxis: {
title: {
text: 'Jumlah Penduduk'
}
},
series:
[
<?php
// file koneksi php
$server = "localhost";
$username = "root";
$password = "";
$database = "db_chart";
mysql_connect($server,$username,$password) or die("Koneksi gagal");
mysql_select_db($database) or die("Database tidak bisa dibuka");
$sql = "SELECT * from datapenduduk"; // file untuk mengakses ke tabel database
$query = mysql_query( $sql ) or die(mysql_error());
while($ambil = mysql_fetch_array($query)){
$provinsi=$ambil['provinsi'];
$sql_jumlah = "SELECT * from datapenduduk where provinsi='$provinsi'";
$query_jumlah = mysql_query( $sql_jumlah ) or die(mysql_error());
while( $data = mysql_fetch_array( $query_jumlah ) ){
$jumlahx = $data['jumlah'];
}
?>
{
name: '<?php echo $provinsi; ?>',
data: [<?php echo $jumlahx; ?>]
},
<?php } ?>
]
});
});
</script>
</head>
<body>
<!-- fungsi yang di tampilkan dibrowser -->
<div id="container" style="min-width: 200px; height: 400px; margin: 0 auto"></div>
</body>
</html>
Share This :
comment 7 Comment
more_vertthe blog was very awesome!!thank you for sharing the article with us. please keep on updating more useful informations... Salesforce training in chennai
2 June 2016 at 16:52I like your presentation which is very much impressive and useful for me to understand the concepts in a very good manner. so please update latest information.
27 January 2017 at 12:19Web Design Company in Chennai
thanks for your tutorial friend..this realy help me do
5 October 2017 at 17:43This article was a really interesting read, information has been presented in a clear and concise manner. Thanks!
24 February 2018 at 18:08ECommerce Website developers in bangalore
Outsource magento ecommerce services india
ielts coaching in gurgaon
3 November 2018 at 17:22That was a great message in my carrier, and It's wonderful commands like mind relaxes with understand words of knowledge by information's.
8 November 2018 at 14:33Java training in Bangalore | Java training in Btm layout
Java training in Bangalore | Java training in Jaya nagar
Java training in Bangalore | Java training in Electronic city
Java training in Chennai | Java training institute in Chennai | Java course in Chennai