数组添加新系列Highchart

时间:2017-06-06 12:51:52

标签: php mysqli highcharts

此代码只是浏览器共享名称系列..

series: [{
    name: 'Man',
    data: <?php echo json_encode($man_array,JSON_NUMERIC_CHECK) ?>
   
  }, {
    name: 'Women',
    data: <?php echo json_encode($woman_array,JSON_NUMERIC_CHECK) ?>

    
  }, {
    name: 'Kind',
    data: <?php echo json_encode($kind_array,JSON_NUMERIC_CHECK) ?>
   
  }, {
    name: 'User',
    data:<?php echo json_encode($user_array,JSON_NUMERIC_CHECK) ?>
   
  }]

Example

如何创作系列剧:女人,系列:男人......请帮帮我......

//Include Koneksi
$koneksi     = mysqli_connect("localhost", "root", "", "simcard");
// $bulan       = mysqli_query($koneksi, "SELECT bulan FROM penjualan WHERE tahun='2017' order by id asc");

//Membuat Query
$q=mysqli_query($koneksi, "SELECT * FROM penduduk");
$a=mysqli_query($koneksi, "SELECT * FROM card");


$man_array=array();
$woman_array=array();
$kind_array=array();
$user_array=array();
while($r=mysqli_fetch_array($q)){
    $man_array[]= $r["man"];
    $woman_array[]= $r["woman"];
}
while($f=mysqli_fetch_array($a)){
    $kind_array[]=$f["kind"];
    $user_array[]= $f["user"];
}

这一个高图代码任何错误的代码..?没有使用颜色没问题。

$('#view').highcharts({
       chart: {
        type: 'column'
    },
    title: {
        text: 'Stacked column chart'
    },
    xAxis: {
        categories: ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas']
    },
    yAxis: {
        min: 0,
        title: {
            text: 'Total'
        },
        stackLabels: {
            enabled: true,
            style: {
                fontWeight: 'bold',
                color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'
            }
        }
    },
    legend: {
        align: 'right',
        x: -30,
        verticalAlign: 'top',
        y: 25,
        floating: true,
        backgroundColor: (Highcharts.theme && Highcharts.theme.background2) || 'white',
        borderColor: '#CCC',
        borderWidth: 1,
        shadow: false
    },
    tooltip: {
        headerFormat: '<b>{point.x}</b><br/>',
        pointFormat: '{series.name}: {point.y}<br/>Total: {point.stackTotal}'
    },
    plotOptions: {
        column: {
            //stacking: 'normal',
            dataLabels: {
                enabled: true,
                color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white'
            }
        }
    },

This Page View source html series.

series: [{
    name: 'Man',
    data: []   
    
  }, {
    name: 'Women',
    data: []
    
  }, {
    name: 'Kind',
     data: []    
  }, {
    name: 'User',
    data:[]   
  }]
		
    });
});

1 个答案:

答案 0 :(得分:0)

你的图表会是这样的,Fiddle sample。所以用下面的代码替换。另请检查Data from a database

<?php
    $man_array=array();
    $woman_array=array();
    $kind_array=array();
    $user_array=array();
    while($r=mysqli_fetch_array($q)){
        $man_array[]= $r["man"];
        $woman_array[]= $r["woman"];
    }
    while($f=mysqli_fetch_array($a)){
        $kind_array[]=$f["kind"];
        $user_array[]= $f["user"];
    }

    ?>
  series: [{
    name: 'Man',
    data: <?php echo json_encode($man_array,JSON_NUMERIC_CHECK) ?>,
    color: 'red'
  }, {
    name: 'Women',
    data: <?php echo json_encode($woman_array,JSON_NUMERIC_CHECK) ?>,

    color: 'black'
  }, {
    name: 'Kind',
    data: <?php echo json_encode($kind_array,JSON_NUMERIC_CHECK) ?>,
    color: 'green'
  }, {
    name: 'User',
    data:<?php echo json_encode($user_array,JSON_NUMERIC_CHECK) ?>,
    color: 'blue'
  }]