user2660267
user2660267

Reputation: 991

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.

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

Upvotes: 0

Views: 882

Answers (1)

Ashwani
Ashwani

Reputation: 3481

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],
        ]);

Upvotes: 1

Related Questions