未捕获的TypeError:无法读取属性' arrayToDataTable'未定义的

时间:2014-05-28 07:45:38

标签: jquery ajax google-visualization

我正面临这个错误,不知道为什么会出现这个错误。我使用的是codeigniter,这是jquery错误。

这是我的查看页面

<script>
$(function() {
    $("#accordion").accordion({
        collapsible: true,
        heightStyle: "content"
    });
});

var data = google.visualization.arrayToDataTable([
    ['Attendance Type', 'Count'],
    ['Present', <?php echo $student_attendance_count['present']; ?>],
    ['Absent', <?php echo $student_attendance_count['absent']; ?>],
    ['On Leave', <?php echo $student_attendance_count['leave']; ?>],
    ['Attendance Not Maked', <?php echo $attendance_not_marked; ?>]
]);

var options = {
    title: 'My Daily Activities'
};

var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(data, options);
</script>

这是我的HTML页面,请查看此内容以供参考。如果您需要更多详细信息,我将在此处添加。我不知道这个错误是怎么来的。

<div id="accordion">
<h3><span class="accordion_header">Student Strength</span></h3>
<div>
    <table>
        <tr>
            <td>
                <div id="chart_div" style="width: 500px; height: 300px;"></div>
            </td>
            <td style="vertical-align: top">
                <table class="list">
                    <tr>
                        <td style="width: 200px;"><b>Total student</b></td>
                        <td style="width: 50px;" class="text-right"><?php echo $total_student_count; ?></td>
                    </tr>
                    <tr>
                        <td class="attendance_color_present"><b>Present</b></td>
                        <td class="text-right attendance_color_present"><?php echo $student_attendance_count['present']; ?></td>
                    </tr>
                    <tr>
                        <td class="attendance_color_absent"><b>Absent</b></td>
                        <td class="text-right attendance_color_absent"><?php echo $student_attendance_count['absent']; ?></td>
                    </tr>
                    <tr>
                        <td class="attendance_color_leave"><b>Leave</b></td>
                        <td class="text-right attendance_color_leave"><?php echo $student_attendance_count['leave']; ?></td>
                    </tr>
                    <tr>
                        <td><b>Attendance Not Marked</b></td>
                        <td class="text-right"><?php echo $attendance_not_marked =  $total_student_count - ($student_attendance_count['present'] + $student_attendance_count['absent'] + $student_attendance_count['leave']); ?></td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>

</div>

<h3><span class="accordion_header">Attendance Details</span></h3>
<div>
    <div class="data_listing" style="margin-left: auto">
        <table class="list"  align="center" style="margin: 0px auto; width: 70%">
            <thead>
                <tr>
                    <th style="width: 10%; text-align:center">Sr. No.</th>
                    <th style="width: 60%">Class Name</th>
                    <th style="width: 30%; text-align: center">Attendance Status</th>
                </tr>
            </thead>
            <?php
            $i = 1;
            $attendance_marked = 0;
            foreach ($class_section_attendance as $class) {
                if ($class['attendance_marked'] == 1) {
                    $image = '<img src ="' . base_url() . 'resources/images/icons/tick_circle.png" title="Attendance Marked" alt="Attendance Marked"/>';
                    $attendance_marked++;
                } else {
                    $image = '<img src ="' . base_url() . 'resources/images/icons/cross.png" title="Attendance Not Marked" alt="Attendance Not Marked"/>';
                }
                echo '<tr>';
                echo '<td style="text-align:center">' . $i++ . '</td>';
                echo '<td>' . $class['name'] . '</td>';
                echo '<td style="text-align:center">' . $image . '</td>';
                echo '</tr>';
            }
            $not_marked = count($class_section_attendance) - $attendance_marked;
            echo '<tr><td colspan="3" style="text-align:center">Total Classes : <b>' . count($class_section_attendance) . '</b> | Attendaced Marked : <b>' . $attendance_marked . '</b> | Not Marked : <b>' . $not_marked . '</b> </td></tr>';
            ?>
        </table>
    </div>
</div>

</div>

请帮帮我。

1 个答案:

答案 0 :(得分:14)

确保正确加载Google Visualization API。

这里的文件: https://google-developers.appspot.com/chart/interactive/docs/basic_load_libs

你可能需要这样的东西:

<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">

  // Load the Visualization API library and the piechart library.
  google.load('visualization', '1.0', {'packages':['corechart']});
  google.setOnLoadCallback(drawChart);
     // ... draw the chart...
</script>