简体   繁体   English

使用JSON数据无法显示Google图表

[英]Google chart not display on using json data

I am using google chart api.I use json data to bind with datatabel in google chart.I call json data through ajax call.Json data comes properly then i parse this data and save it into array.When I give the array value to DataTabel of x axis then google chart not display.please help me. 我正在使用谷歌图表API。我使用json数据与谷歌图表中的datatabel绑定。我通过ajax调用来调用json数据.Json数据正确,然后我解析此数据并将其保存到数组中。当我将数组值提供给DataTabel时X轴的Google图表无法显示。请帮助我。

<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>

That is a typo error. 那是一个错字错误。 Use 采用

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

and try this format to prevent mistakes: 并尝试使用以下格式以防止错误:

var data = google.visualization.arrayToDataTable([
          [title, 'countries'],
          [Name[0],  1000],
          [Name[1],  1170],
        ]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM