0

例如,我有一个使用大量数组来存储数据的表

$count = array( "1111", "2222", "3333", "4444" );

和一张桌子

<table id="datatable1" border="1">
    <thead>
    <tr>
        <th>
            Count1
        </th>
        <th>
            Count2
        </th>
    </tr>
    </thead>
    <tbody>
    <?php foreach ($count as $count1): ?>
        <tr>
            <td>
                <?php echo $count1 ?>
            </td>
            <td>
                &nbsp;<?php echo $count1 ?>
            </td>
        </tr>
    <?php endforeach; ?>
    </tbody>
</table>

我想通过单击按钮来绘制图表

<input type="button" id="butt"  value="Click me" onclick="clk()">

和绘制图表的函数

 function clk() {
        $('#container').highcharts({
            data: {
                table: document.getElementById('datatable1')
            },
            chart: {
                type: 'column'
            },
            title: {
                text: 'Data extracted from a HTML table in the page'
            },
            yAxis: {
                allowDecimals: false,
                title: {
                    text: 'Units'
                }
            },
            tooltip: {
                formatter: function() {
                    return '<b>'+ this.series.name +'</b><br/>'+
                        this.y +' '+ this.x.toLowerCase();
                }
            }
        });
    }

ofc 我有一个用于图表的 div 容器

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

但我点击按钮后,没有图表。页面源码中有一个图表代码,但是这个图表没有内容。我认为问题出在我的表数据上,我是通过 foreach 从数组中获取的,但我需要使用这种方式来获取表数据。那么我应该怎么做才能绘制图表呢?

4

0 回答 0