Kaskus

Tech

wolfzmusAvatar border
TS
wolfzmus
[NANYA] Ada yang salah kah ama codingan ane???
Jadi gini ane punya coding framework php, dan ane mau munculin chart berdasarkan filter yang udah ada, yaitu buyer ama peridoe. Untuk maslah even ane dah bisa ampe querynya juga dah berhasil, masalahnya pas di function datasets di cahrt.jsnya. Jadi gini codingan ane yang di controler

Code:

$orderstatusdetail = $this->orderstatusdetail;
$buyercode = $_GET['buyer'];
$dari = $_GET['dari'];
$sampai = $_GET['sampai'];

//$json = array();

//var_dump($buyercode);




// var_dump(implode('","', $aray));
//$buyercode=implode('","', $aray);



//$buyer =
$buyers = explode(",", $buyercode);
$a = 0;
$json = array();
$BuyerName = "";
foreach($buyers as $buyer) {
$buyercode =$buyer;
//var_dump($buyercode);
$b = 0;
$qty = array();
$CounterBuyer = $orderstatusdetail->select($buyercode,$dari,$sampai);
//var_dump($orderstatusdetail->select($buyercode,$dari,$sampai));
while ( $sItem = $CounterBuyer['items']->fetch_assoc()) {
$qty[] = $sItem['total'];
$BuyerName = $sItem['BuyerName'];
}
$totals = implode(",",$qty);

$json[] = "{
label: '".$BuyerName."',
fillColor: 'rgba(151,187,205,0.2)',
strokeColor: 'rgba(151,187,205,1)',
pointColor: 'rgba(151,187,205,1)',
pointStrokeColor: '#fff',
pointHighlightFill: '#fff',
pointHighlightStroke: 'rgba(151,187,205,1)',
data: [".$totals."]
}";
}

//$json['data'] = implode(",",$json);
var_dump($json['data']);
if ($json == null) {
$json['data'] = [];
}

header('Content-Type: application/json');
//var_dump($json);
echo json_encode($json);


nah di javascriptnya ane pake js.ini (ini berjalan lancar pas instal jsnya)

Code:

var Button = function() {
"use strict";
var runchart = function () {
$('#btnchart').on('click', function() {
var target = $(this).attr('data-target');
var oderby = $(this).attr('order-by');
var buyer = $(".js-example-basic-multiple").val();
var dari = $("#tglfrom").val();
var dateStart = new Date(dari);
var sampai = $("#tglto").val();
var dateEnd = new Date(sampai);
var dateLoop = [];

//console.log(dateStart);

var arrM = [];
arrM.push(dari);
arrM.push(sampai);
arrM.push(buyer);

if(dari!="" & sampai!="" & buyer!= null)
{
while (dateEnd >= dateStart) {
dateLoop.push((dateStart.getMonth() + 1) + '/' + dateStart.getFullYear());
var newDate = dateStart.setDate(dateStart.getMonth() + 1);
dateStart.setMonth(dateStart.getMonth() + 1);
//dari.add(1,'month');
}
$.getJSON( host+""+target+"/"+oderby+"?buyer="+buyer+"&dari="+dari+"&sampai="+sampai, function (json){

for(var i in data) {
player.push("Player " + data[i].playerid);
score.push(data[i].score);
}

console.log(json.data);
//Option bar chart
var options = {
// Sets the chart to be responsive
responsive: true,

//Boolean - Whether the scale should start at zero, or an order of magnitude down from the lowest value
scaleBeginAtZero: true,

//Boolean - Whether grid lines are shown across the chart
scaleShowGridLines: true,

//String - Colour of the grid lines
scaleGridLineColor: "rgba(0,0,0,.05)",

//Number - Width of the grid lines
scaleGridLineWidth: 1,

//Boolean - If there is a stroke on each bar
barShowStroke: true,

//Number - Pixel width of the bar stroke
barStrokeWidth: 2,

//Number - Spacing between each of the X value sets
barValueSpacing: 5,

//Number - Spacing between data sets within X values
barDatasetSpacing: 1,

tooltipTemplate: "<%= value %> Files",

multiTooltipTemplate: "<%= value + '$' %>",

//String - A legend template
//legendTemplate: '<ul class="<%=name.toLowerCase()%>-legend"><% for (var i=0; i<datasets.length; i++){%><li><span style="background-color:<%=datasets[i].fillColor%>"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>'
};

var data = {

labels: [dateLoop],
datasets: [json.data]
};
var ctx = $("#chart1").get(0).getContext("2d");
// This will get the first returned node in the jQuery collection.
var chart1 = new Chart(ctx).Line(data, options);
//generate the legend
var legend = chart1.generateLegend();
//and append it to your page somewhere
$('#chart1Legend').append(legend);
}); // END OF getJson ------------------------------------------------------------
}
else
{
swal({
title: "Please fill filter!!!",
type : "warning"
});
}

});
}

return {
init: function (){
runchart();
}
}
}();


Nah maslahnya ane mau munculin ke datasets gitu, cuman pakah dataset codingan ane bener apa kagak?? Sebenarnya bisa gak sich datasets itu di looping lagi??
Banyak yang pasti bertanya bukannya ini dah di buat ya dio tread lain, Iya bener, cuman maslahanya GAK ADA YANG JAWAB, yang jawab sich cuman satu, tapi ane berharap yang ini di jawab bener2 dah. Mohon pencerahan.



NOTE :
Quote:


Yang ane qoute + tanda merah itu berfungsi gak sich?? apa ane harus bijimane yah supaya bisa multiple yang ane mau.
0
497
0
GuestAvatar border
Komentar yang asik ya
GuestAvatar border
Komentar yang asik ya
Komunitas Pilihan