显示高图的图形

时间:2015-08-06 12:43:18

标签: php highcharts

我有一个很大的问题,我无法解决它。我想显示一个高图的图形。连接成功建立但图形没有显示。我尝试了JSON方法,我尝试了非常方法,但没有显示。我认为问题来自HTML / CSS页面的结构,但我不知道。这是我的代码:这是显示图形的代码的重要部分:

   <body>
      <div id="chart_opérateur" style="height: 250px;"></div>
      <script  type="text/javascript">
     new Morris.Donut({
  // ID of the element in which to draw the chart.
  element: 'chart_opérateur',
  // Chart data records -- each entry in this array corresponds to a point on
  // the chart.
  data: [
     <?php 
      $req = "SELECT count(nombre_sms) as nb_ooredoo FROM service_jet where            id_utilisateur between 20000000 and 25999999 " ;
     global $cnx ; 
      $res = $cnx->prepare($req) ; 
      $res->execute() ; 
      while ($stats = $res->fetch()) {
   ?>
    { label: 'Ooredoo', value: <?php echo $stats['nb_ooredoo'] ?> },
    <?php } ?>
    <?php
    $req = "SELECT count(nombre_sms) as nb_telecom from service_jet where id_utilisateur between 92000000 and 99999999  " ;
    global $cnx ; 
      $res = $cnx->prepare($req) ; 
      $res->execute() ; 
      while ($stats = $res->fetch()) {
   ?>
    { label: 'Telecom', value:<?php echo $stats['nb_telecom'] ?> },
    <?php } ?>
    <?php
    $req = "select COUNT(nombre_sms) as nb_orange from service_jet where id_utilisateur between 50000000 and 59999999 " ; 
    global $cnx ; 
      $res = $cnx->prepare($req) ; 
      $res->execute() ; 
      while ($stats = $res->fetch()) {
   ?>
    { label: 'Orange', value:<?php echo $stats['nb_orange'] ?> },
    <?php } ?>
    }
  ],
  <?php } ?>
  // The name of the data record attribute that contains x-values.
  xkey: 'Opérateur',
  // A list of names of data record attributes that contain y-values.
  ykeys: ['value'],
  // Labels for the ykeys -- will be displayed when you hover over the
  // chart.
  labels: ['Value']
});
    </script>

2 个答案:

答案 0 :(得分:0)

我找到了一个非常有趣的页面,你可以在那里找到一些问题的帮助,我使用这个页面从MySQL制作了一个图形:http://blueflame-software.com/blog/using-highcharts-with-php-and-mysql/

另一页可能是:http://blueflame-software.com/blog/column-chart-with-data-from-mysql-using-highcharts/

答案 1 :(得分:0)

data.php:

<?php
$db = mysqli_connect('localhost', 'root') or die("Error " . mysqli_error($db)); 
mysqli_set_charset($db,"utf8");

// on sélectionne la base 
$db_selected=mysqli_select_db($db,'outil_echantillonnage_et_analyse_de_donnees') or die("Error in the consult.." . mysqli_error($db)); 

$rows = array();
$rows['ooredoo']['Jan'] = 'nombre_sms';
$rows['ooredoo']['Feb'] = 'nombre_sms';
$rows['ooredoo']['Mar'] = 'nombre_sms';
$rows['ooredoo']['Apr'] = 'nombre_sms';
$rows['ooredoo']['May'] = 'nombre_sms';
$rows['ooredoo']['Jun'] = 'nombre_sms';
$rows['ooredoo']['Jul'] = 'nombre_sms';
$rows['ooredoo']['Aug'] = 'nombre_sms';
$rows['ooredoo']['Sep'] = 'nombre_sms';
$rows['ooredoo']['Oct'] = 'nombre_sms';
$rows['ooredoo']['Nov'] = 'nombre_sms';
$rows['ooredoo']['Dec'] = 'nombre_sms';
$sth = mysqli_query($db,"SELECT count(nombre_sms) as nb_ooredoo FROM service_jet where date_inscri between '2010-01-01' and '2010-01-31' and id_utilisateur between 20000000 and 25999999");
while( $r = mysqli_fetch_array($sth)) 
{ 
    $rows['ooredoo']['Jan']= $r['nb_ooredoo'];
}
$sth = mysqli_query($db,"SELECT count(nombre_sms) as nb_ooredoo FROM service_jet where date_inscri between' 2010-02-01' and '2010-02-29' and id_utilisateur between 20000000 and 25999999");
while( $r = mysqli_fetch_array($sth)) 
{ 
    $rows['ooredoo']['Feb']= $r['nb_ooredoo'];
}
$sth = mysqli_query($db,"SELECT count(nombre_sms) as nb_ooredoo FROM service_jet where date_inscri between '2010-03-01' and '2010-03-31' and  id_utilisateur between 20000000 and 25999999");
while( $r = mysqli_fetch_array($sth)) 
{ 
    $rows['ooredoo']['Mar']= $r['nb_ooredoo'];
}
$sth = mysqli_query($db,"SELECT count(nombre_sms) as nb_ooredoo FROM service_jet where date_inscri between '2010-04-01' and '2010-04-30' and  id_utilisateur between 20000000 and 25999999");
while( $r = mysqli_fetch_array($sth)) 
{ 
    $rows['ooredoo']['Avr']= $r['nb_ooredoo'];
}
$sth = mysqli_query($db,"SELECT count(nombre_sms) as nb_ooredoo FROM service_jet where date_inscri between '2010-05-01' and '2010-05-31' and  id_utilisateur between 20000000 and 25999999");
while( $r = mysqli_fetch_array($sth)) 
{ 
    $rows['ooredoo']['May']= $r['nb_ooredoo'];
}
$sth = mysqli_query($db,"SELECT count(nombre_sms) as nb_ooredoo FROM service_jet where date_inscri between '2010-06-01' and '2010-06-30' and  id_utilisateur between 20000000 and 25999999");
while( $r = mysqli_fetch_array($sth)) 
{ 
    $rows['ooredoo']['Jun']= $r['nb_ooredoo'];
}
$sth = mysqli_query($db,"SELECT count(nombre_sms) as nb_ooredoo FROM service_jet where date_inscri between '2010-07-01' and '2010-07-31' and  id_utilisateur between 20000000 and 25999999");
while( $r = mysqli_fetch_array($sth)) 
{ 
    $rows['ooredoo']['Jul']= $r['nb_ooredoo'];
}
$sth = mysqli_query($db,"SELECT count(nombre_sms) as nb_ooredoo FROM service_jet where date_inscri between '2010-08-01' and '2010-08-31' and  id_utilisateur between 20000000 and 25999999");
while( $r = mysqli_fetch_array($sth)) 
{ 
    $rows['ooredoo']['Aug']= $r['nb_ooredoo'];
}
$sth = mysqli_query($db,"SELECT count(nombre_sms) as nb_ooredoo FROM service_jet where date_inscri between '2010-09-01' and '2010-09-30' and  id_utilisateur between 20000000 and 25999999");
while( $r = mysqli_fetch_array($sth)) 
{ 
    $rows['ooredoo']['Sep']= $r['nb_ooredoo'];
}
$sth = mysqli_query($db,"SELECT count(nombre_sms) as nb_ooredoo FROM service_jet where date_inscri between '2010-10-01' and '2010-10-31' and  id_utilisateur between 20000000 and 25999999");
while( $r = mysqli_fetch_array($sth)) 
{ 
    $rows['ooredoo']['Oct']= $r['nb_ooredoo'];
}
$sth = mysqli_query($db,"SELECT count(nombre_sms) as nb_ooredoo FROM service_jet where date_inscri between '2010-11-01' and '2010-11-30' and  id_utilisateur between 20000000 and 25999999");
while( $r = mysqli_fetch_array($sth)) 
{ 
    $rows['ooredoo']['Nov']= $r['nb_ooredoo'];
}
$sth = mysqli_query($db,"SELECT count(nombre_sms) as nb_ooredoo FROM service_jet where date_inscri between '2010-12-01' and '2010-12-31' and  id_utilisateur between 20000000 and 25999999");
while( $r = mysqli_fetch_array($sth)) 
{ 
    $rows['ooredoo']['Dec']= $r['nb_ooredoo'];
}





$rows1 = array();
$rows1['telecom']['Jan'] = 'nombre_sms';
$rows1['telecom']['Feb'] = 'nombre_sms';
$rows1['telecom']['Mar'] = 'nombre_sms';
$rows1['telecom']['Apr'] = 'nombre_sms';
$rows1['telecom']['May'] = 'nombre_sms';
$rows1['telecom']['Jun'] = 'nombre_sms';
$rows1['telecom']['Jul'] = 'nombre_sms';
$rows1['telecom']['Aug'] = 'nombre_sms';
$rows1['telecom']['Sep'] = 'nombre_sms';
$rows1['telecom']['Oct'] = 'nombre_sms';
$rows1['telecom']['Nov'] = 'nombre_sms';
$rows1['telecom']['Dec'] = 'nombre_sms';
$sth = mysqli_query($db,"SELECT count(nombre_sms) as nb_telecom FROM service_jet where date_inscri between '2010-01-01' and '2010-01-31' and id_utilisateur between 92000000 and 99999999");
while( $r = mysqli_fetch_array($sth)) 
{ 
    $rows1['telecom']['Jan']= $r['nb_telecom'];
}
$sth = mysqli_query($db,"SELECT count(nombre_sms) as nb_telecom FROM service_jet where date_inscri between' 2010-02-01' and '2010-02-29' and id_utilisateur between 92000000 and 99999999");
while( $r = mysqli_fetch_array($sth)) 
{ 
    $rows1['telecom']['Feb']= $r['nb_telecom'];
}
$sth = mysqli_query($db,"SELECT count(nombre_sms) as nb_telecom FROM service_jet where date_inscri between '2010-03-01' and '2010-03-31' and  id_utilisateur between 92000000 and 99999999");
while( $r = mysqli_fetch_array($sth)) 
{ 
    $rows1['telecom']['Mar']= $r['nb_telecom'];
}
$sth = mysqli_query($db,"SELECT count(nombre_sms) as nb_telecom FROM service_jet where date_inscri between '2010-04-01' and '2010-04-30' and  id_utilisateur between 92000000 and 99999999");
while( $r = mysqli_fetch_array($sth)) 
{ 
    $rows1['telecom']['Avr']= $r['nb_telecom'];
}
$sth = mysqli_query($db,"SELECT count(nombre_sms) as nb_telecom FROM service_jet where date_inscri between '2010-05-01' and '2010-05-31' and  id_utilisateur between 92000000 and 99999999");
while( $r = mysqli_fetch_array($sth)) 
{ 
    $rows1['telecom']['May']= $r['nb_telecom'];
}
$sth = mysqli_query($db,"SELECT count(nombre_sms) as nb_telecom FROM service_jet where date_inscri between '2010-06-01' and '2010-06-30' and  id_utilisateur between 92000000 and 99999999");
while( $r = mysqli_fetch_array($sth)) 
{ 
    $rows1['telecom']['Jun']= $r['nb_telecom'];
}
$sth = mysqli_query($db,"SELECT count(nombre_sms) as nb_telecom FROM service_jet where date_inscri between '2010-07-01' and '2010-07-31' and  id_utilisateur between 92000000 and 99999999");
while( $r = mysqli_fetch_array($sth)) 
{ 
    $rows1['telecom']['Jul']= $r['nb_telecom'];
}
$sth = mysqli_query($db,"SELECT count(nombre_sms) as nb_telecom FROM service_jet where date_inscri between '2010-08-01' and '2010-08-31' and  id_utilisateur between 92000000 and 99999999");
while( $r = mysqli_fetch_array($sth)) 
{ 
    $rows1['telecom']['Aug']= $r['nb_telecom'];
}
$sth = mysqli_query($db,"SELECT count(nombre_sms) as nb_telecom FROM service_jet where date_inscri between '2010-09-01' and '2010-09-30' and  id_utilisateur between 92000000 and 99999999");
while( $r = mysqli_fetch_array($sth)) 
{ 
    $rows1['telecom']['Sep']= $r['nb_telecom'];
}
$sth = mysqli_query($db,"SELECT count(nombre_sms) as nb_telecom FROM service_jet where date_inscri between '2010-10-01' and '2010-10-31' and  id_utilisateur between 92000000 and 99999999");
while( $r = mysqli_fetch_array($sth)) 
{ 
    $rows1['telecom']['Oct']= $r['nb_telecom'];
}
$sth = mysqli_query($db,"SELECT count(nombre_sms) as nb_telecom FROM service_jet where date_inscri between '2010-11-01' and '2010-11-30' and  id_utilisateur between 92000000 and 99999999");
while( $r = mysqli_fetch_array($sth)) 
{ 
    $rows1['telecom']['Nov']= $r['nb_telecom'];
}
$sth = mysqli_query($db,"SELECT count(nombre_sms) as nb_telecom FROM service_jet where date_inscri between '2010-12-01' and '2010-12-31' and  id_utilisateur between 92000000 and 99999999");
while( $r = mysqli_fetch_array($sth)) 
{ 
    $rows1['telecom']['Dec']= $r['nb_telecom'];
}

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

print json_encode($result, JSON_NUMERIC_CHECK);

mysqli_close($db);
?>

的index.php:

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>Highcharts Example</title>
</head>
    <body>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
        <script type="text/javascript">
$(function () {
    var chart;
    $(document).ready(function() {
        $.getJSON("data.php", function(json) {

            chart = new Highcharts.Chart({
                chart: {
                    renderTo: 'container',
                    type: 'line',
                    marginRight: 130,
                    marginBottom: 25
                },
                title: {
                    text: 'Ooredoo vs. Telecom',
                    x: -20 //center
                },
                subtitle: {
                    text: '',
                    x: -20
                },
                xAxis: {
                    categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
                },
                yAxis: {
                    title: {
                        text: 'Amount'
                    },
                    plotLines: [{
                        value: 0,
                        width: 1,
                        color: '#808080'
                    }]
                },
                tooltip: {
                    formatter: function() {
                            return '<b>'+ this.series.name +'</b><br/>'+
                            this.x +': '+ this.y;
                    }
                },
                legend: {
                    layout: 'vertical',
                    align: 'right',
                    verticalAlign: 'top',
                    x: -10,
                    y: 100,
                    borderWidth: 0
                },
                series: json
            });
        });

    });

});
        </script>

  <script src="http://code.highcharts.com/highcharts.js"></script>
  <script src="http://code.highcharts.com/modules/exporting.js"></script>

<div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div>

    </body>
</html>