0

我正在使用谷歌图表api。我使用json数据与谷歌图表中的数据表绑定。我通过ajax调用调用json数据。Json数据正确然后我解析这些数据并将其保存到数组中。当我将数组值提供给DataTabel x 轴然后谷歌图表不显示。请帮助我。

<script type="text/javascript">
    google.load('visualization', '1', { packages: ['corechart'] });
    google.setOnLoadCallback(drawChart);

    function drawChart() {
        var Name = [];
        var jsonData = $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: "NewDashboard.aspx/DisplayData",
            data: "{}",
            dataType: "json",
            success: function (result) {

                var contact = JSON.parse(result.d);
                for (var i = 0; i < contact.length; i++) {

                    Name.push([contact[i].VehicleName]);

                }




                var wrapper = new google.visualization.ChartWrapper({
                    chartType: 'ColumnChart',
                    dataTable: [['',Name[0], Name[1],Name[3]s],
                  ['', 700, 300, 400]],
                    options: { 'title': 'Countries' },
                    containerId: 'visualization'
                });

                wrapper.draw();

            },
            error: function (result) {
                alert("Error");
            }
        }); 
    }
</script>
4

1 回答 1

1

那是一个拼写错误。利用

var wrapper = new google.visualization.ChartWrapper({
                    chartType: 'ColumnChart',
                    dataTable: [['',Name[0], Name[1],Name[3]],
                  ['', 700, 300, 400]],
                    options: { 'title': 'Countries' },
                    containerId: 'visualization'
                });

并尝试这种格式以防止错误:

var data = google.visualization.arrayToDataTable([
          [title, 'countries'],
          [Name[0],  1000],
          [Name[1],  1170],
        ]);
于 2013-08-09T10:19:08.040 回答