如何使我的highcharts逆转

时间:2017-06-14 18:20:07

标签: javascript php mysqli graph highcharts

我想使用highcharts绘制图形。 问题是,为什么我的x轴和y轴反转。我正在使用json为我的系列。 我被卡住了。这个怎么样 this is how my program works. i want to reverse it but i dont know what to do

继承人的代码



  <script type="text/javascript">
    var chart;
    $(function () {
         Highcharts.setOptions({
        global: {
            useUTC: false,
            
        },
        lang: {
          decimalPoint: ',',
          thousandsSep: '.'
        }
    });
      
      $(document).ready(function() {
        $.getJSON("dataline.php", function(json) {
        
          chart = new Highcharts.Chart({
            chart: {
              renderTo: 'mygraph',
              type: 'bar'
              
            },
            title: {
              text: 'Debet dan Kredit'
              
            },
            subtitle: {
              text: '2017'
            
            },
            xAxis: {
              categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
              title:{
                text: 'Total (Rp)'
              }
            },
            yAxis: {
              title: {
                text: 'Bulan'
              },
              plotLines: [{
                value: 0,
                width: 1,
                color: '#808080'
              }]
            },

            tooltip: {
              //fungsi tooltip, ini opsional, kegunaan dari fungsi ini 
              //akan menampikan data di titik tertentu di grafik saat mouseover
              formatter: function() {
                  return '<b>'+ this.series.name +'</b><br/>'+
                  this.x +': Rp. '+ Highcharts.numberFormat(this.point.y,1,',','.');
                  
              },
            },
            legend: {
              layout: 'vertical',
              align: 'right',
              verticalAlign: 'top',
              x: -10,
              y: 120,
              borderWidth: 0
            },
            //series adalah data yang akan dibuatkan grafiknya, diisi data
            series: json
          });
        });
      
      });
      
    });
    </script>
&#13;
<div class="container" style="margin-top:20px">
  <div class="col-md-10">
    <div class="panel panel-primary">
      <div class="panel-heading">Grafik Seluruh Total Debet dan Kredit</div>
        <div class="panel-body">
          <div id ="mygraph"></div>
        </div>
    </div>
  </div>
</div>
&#13;
&#13;
&#13;

和我的dataline.php

&#13;
&#13;
<?php
include "connection.php";
session_start();
$level = $_SESSION['level'];
$toko 	=$_SESSION['id_toko'];
//Data untuk debet 

if($level =='manajer' || $level=='bendahara'){
	$query = mysqli_query($connection,"select month(tanggal), sum(debet) as tot from jurnalumum_detail  GROUP BY DATE_FORMAT(jurnalumum_detail.tanggal,'%m') ORDER BY month(tanggal) desc LIMIT 1;");
}else if ($level=='owner'){
$query = mysqli_query($connection,"select month(tanggal), sum(debet) as tot from jurnalumum_detail GROUP BY DATE_FORMAT(jurnalumum_detail.tanggal,'%m') ORDER BY month(tanggal) desc LIMIT 1;");}
$rows = array();
$rows['name'] = 'Debet';
 while ($row=mysqli_fetch_array($query)) {
        $lastmonth = $row['month(tanggal)'];
    }
    for($i = 1 ; $i <= $lastmonth ; $i++){
    	if($level =='manajer' || $level=='bendahara'){
    		$query = mysqli_query($connection,"select month(tanggal), sum(debet) as tot from jurnalumum_detail where month(tanggal) = '$i' AND id_toko='$toko' GROUP BY DATE_FORMAT(jurnalumum_detail.tanggal,'%m') ;");
    	}else if($level=='owner'){
        $query = mysqli_query($connection,"select month(tanggal), sum(debet) as tot from jurnalumum_detail where month(tanggal) = '$i' GROUP BY DATE_FORMAT(jurnalumum_detail.tanggal,'%m') ;"); }
        $jumlah = mysqli_num_rows($query);
        if ($jumlah == 0){
        	$rows['data'][] = 0;
    }else{
        while ($row=mysqli_fetch_array($query)) {
        $row;
        $rows['data'][] = $row['tot'];
    }   
    }
}


//Data untuk kredit
$query = mysqli_query($connection,"select month(tanggal), sum(kredit) as tot from jurnalumum_detail GROUP BY DATE_FORMAT(jurnalumum_detail.tanggal,'%m') ORDER BY month(tanggal) desc LIMIT 1;");
$rows1 = array();
$rows1['name'] = 'Kredit';
while ($row=mysqli_fetch_array($query)) {
        $lastmonth = $row['month(tanggal)'];
    }
    for($i = 1 ; $i <= $lastmonth ; $i++){
		if($level=='manajer' || $level=='bendahara'){
        $query = mysqli_query($connection,"select month(tanggal), sum(kredit) as tot from jurnalumum_detail where month(tanggal) = '$i' AND id_toko = '$toko' GROUP BY DATE_FORMAT(jurnalumum_detail.tanggal,'%m') ;");}
        $jumlah = mysqli_num_rows($query);
        if ($jumlah == 0){
        	$rows1['data'][] = 0;
    }else{
        while ($row=mysqli_fetch_array($query)) {
        $row;
        
        $rows1['data'][] =  $row['tot'];
    }   
    }
}

$result = array();
array_push($result,$rows);
array_push($result,$rows1);

print json_encode($result, JSON_NUMERIC_CHECK);



?>
&#13;
&#13;
&#13;

感谢您的帮助!我真的需要这个

1 个答案:

答案 0 :(得分:1)

在解码JSON之前反转你的数组

$data = array_reverse($result);
echo json_encode($data, JSON_NUMERIC_CHECK);