Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
google pie chart not working for me. every thing is fine webmethod also return value
but error in this line(data.addRow([jsonData[i].Text, jsonData[i].Value]);) any one solve my question thank regards

What I have tried:

HTML
<script type="text/javascript">

      // VISUALIZATION API AND THE PIE CHART PACKAGE.
      google.load("visualization", "1", { packages: ["corechart"] });

      google.setOnLoadCallback(createPIE);
      

      function createPIE() {
          var options = {
              title: 'Downtime Analysis',
              colors: ['#888', 'orange'],
              is3D: true
          };
          //alert("");
          $.ajax({
              url: "webmethod.aspx/GetpieChartweb",
              dataType: "json",
              type: "POST",
              contentType: "application/json; charset=utf-8",
              success: function(jsonData) {
              var data = new google.visualization.DataTable();
              
                  // assumes "word" is a string and "count" is a number
                  data.addColumn('string', 'Text');
                  data.addColumn('number', 'Value');
                  // CREATE A DataTable AND ADD THE ARRAY (WITH DATA) IN IT.
                  //var figures = google.visualization.arrayToDataTable(arrValues)

                  // THE TYPE OF CHART (PieChart IN THIS EXAMPLE).
                  // var chart = new google.visualization.PieChart(document.getElementById('divpiechart'));
                  var len = jsonData.d.length;
                  // alert(len);
                  for (var i = 0; i < len; i++) {
                      alert(i);
                      //data.addRow([jsonData[i].Text, jsonData[i].value]);
                      data.addRow([jsonData[i].Text, jsonData[i].Value]); // error in this line 
                      //alert([jsonData[i].Text]); this alert not come
                  }
                  var chart = new google.visualization.PieChart(document.getElementById('divpiechart'));
                  chart.draw(data, options);             // DRAW GRAPH WITH THE DATA AND OPTIONS.

              },
              error: function(XMLHttpRequest, textStatus, errorThrown) {
                  alert('Got an Error');
              }
          });
      }
</script>
Posted
Updated 2-Aug-16 21:50pm
Comments
Suvendu Shekhar Giri 3-Aug-16 2:22am    
Share the error details.
Nethaji chennai 3-Aug-16 2:36am    
for (var i = 0; i < len; i++) {
alert(i);// this alert displayed
//data.addRow([jsonData[i].Text, jsonData[i].value]);
data.addRow([jsonData[i].Text, jsonData[i].Value]); // error in this line
//alert([jsonData[i].Text]); this alert not come
}
The Praveen Singh 3-Aug-16 2:50am    
data.addRow([jsonData[i].Text, jsonData[i].Value]);
put alert before above line alert(jsonData[i].Text);
Is data comes ??
Nethaji chennai 3-Aug-16 3:14am    
alert not come
Nethaji chennai 3-Aug-16 3:46am    
data is come alert(jsondat.d[i]. text ) but chart not come

1 solution

alert come after this line also but pie chart not display please reply me
 
Share this answer
 
Comments
Richard Deeming 3-Aug-16 9:59am    
DO NOT post comments as solutions!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900