dounai9294 2016-10-18 18:23
浏览 112

使用MYSQL数据库中的Highchartjs的动态向下钻取图表

Please assist me on finishing this scripts...

First of all, the scripts work flawlessly without any drilldown charts, but if i add drilldown to the scripts, the script shows many error such as id property, etc...

I try to follows Highchart Column Drilldown tutorial including requirement that should included in order the chart to drilldown, but still fails to make it works:

This is my databases:

enter image description here

Below are my scripts without any drilldown which is work without errors..

<?php
require_once('../includes/database.php');

$stmt = mysqli_prepare($con, "SELECT state_name,totals FROM states");
$result = array('state_name' => array(), 'totals' => array());
if ($stmt) {
    mysqli_stmt_execute($stmt);
    mysqli_stmt_bind_result($stmt, $state_name, $totals);
    while (mysqli_stmt_fetch($stmt)) {
        $result['state_name'][] = $state_name;
        $result['totals'][] = (int)$totals;
    }
    mysqli_stmt_close($stmt);
}

?>
<body>
<div id="div-chart"></div>
    <script src="../assets/js/jquery-1.12.3.js"></script>
    <script src="https://code.highcharts.com/highcharts.js"></script>
    <script src="https://code.highcharts.com/modules/data.js"></script>
    <script src="https://code.highcharts.com/modules/drilldown.js">     
    </script>                                                
    <script>
    $(function () {
        $('#div-chart').highcharts({
            chart: {
                type: 'column'
            },
            title: {
                text: 'List of States'
            },
            xAxis: {
                categories: <?php echo json_encode($result['state_name'])   
?>,
                crosshair: true
            },
            yAxis: {
                min: 0,
                title: {
                    text: 'Total'
                }
            },
            plotOptions: {
                column: {
                    pointPadding: 0.2,
                    borderWidth: 0
                }
            },
            series: [{
                name: 'States',
                data: <?php echo json_encode($result['totals']) ?>
            }]
        });
    });
</script>
</body>

Below are output without drilldown attributes:

enter image description here

Below are updated scripts with drilldown attribute that dont work at all:

<?php
require_once('../includes/database.php');

$stmt = mysqli_prepare($con, "SELECT state_name,one,two,three,totals FROM 
states");
$result = array('state_name' => array(), 'one' => array(), 'two' =>   
array(), 'three' => array(), 'totals' => array());
if ($stmt) {
    mysqli_stmt_execute($stmt);
    mysqli_stmt_bind_result($stmt, $state_name, $totals);
    while (mysqli_stmt_fetch($stmt)) {
        $result['state_name'][] = $state_name;
        $result['one'][] = (int)$one;
        $result['two'][] = (int)$two;
        $result['three'][] = (int)$three;
        $result['totals'][] = (int)$totals;
    }
    mysqli_stmt_close($stmt);
}

?>
<body>
<div id="div-chart"></div>
    <script src="../assets/js/jquery-1.12.3.js"></script>
    <script src="https://code.highcharts.com/highcharts.js"></script>
    <script src="https://code.highcharts.com/modules/data.js"></script>
    <script src="https://code.highcharts.com/modules/drilldown.js">
</script>                                                
<script>
    $(function () {
        $('#div-chart').highcharts({
            chart: {
                type: 'column'
            },
            title: {
                text: 'List of States'
            },
            xAxis: {
                categories: <?php echo json_encode($result['state_name']) 
?>,
                crosshair: true
            },
            yAxis: {
                min: 0,
                title: {
                    text: 'Total'
                }
            },
            plotOptions: {
                column: {
                    pointPadding: 0.2,
                    borderWidth: 0
                }
            },
            series: [{
                name: 'States',
                data: [{
                 name: <?php echo json_encode($result['state_name']) ?>,
                 y: <?php echo json_encode($result['totals']) ?>,
                 drilldown: <?php echo json_encode($result['state_name']) ?>
                }]
            }],
            drilldown: {
                series: [{
                    name: <?php echo json_encode($result['state_name']) ?>,
                    id: <?php echo json_encode($result['state_name']) ?>,
                    data: [
                            <?php echo json_encode($result['one']) ?>, 
                            <?php echo json_encode($result['two']) ?>,
                            <?php echo json_encode($result['three']) ?>
                    ]
                }]
            }
        });
    });
</script>
</body>

Please help me out to solve this, I want the chart to drilldown asynchronously, but from mysql databases..

Thank You...

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 ELGamal和paillier计算效率谁快?
    • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
    • ¥15 ubuntu系统下挂载磁盘上执行./提示权限不够
    • ¥15 Arcgis相交分析无法绘制一个或多个图形
    • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
    • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
    • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
    • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
    • ¥30 3天&7天&&15天&销量如何统计同一行
    • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码