Hi,

A JSON string must have its properties double quoted, not single quoted.
Let me know if you still experience issues after fixing this.

On Wed, Mar 23, 2016 at 6:22 AM Md Rehan Moazzam <[email protected]> wrote:

> Hi,
>
> I am trying to provide a json string to googlepie chart but every time its
> saying that json format is invalid.
>
> Please follow the code.
>
> //ASP code
>
> function drawDonutChart(chartType) {
>             //alert('Under Donut Chart');
>
>             var objCombo = {};
>             objCombo.siteURL = window.location.protocol + "//" +
> window.location.host + _spPageContextInfo.siteServerRelativeUrl;
>             objCombo.chartType = chartType;
>
>             var jsonData = $.ajax({
>                 type: "POST",
>                 contentType: 'application/json',
>                 url: 'Dashboard.aspx/GetDonutChartData',
>                 data: JSON.stringify(objCombo),
>                 //beforeSend: function () { alert("before send"); },
>                 //complete: function () { alert("complete"); },
>                 success: function (data) {
>                     var donutChartData = new
> google.visualization.DataTable(data.d);
>                     var options = {
>                         legend: 'right',
>                         pieSliceText: 'value',
>                         pieHole: 0.4,
>                         chartArea: {
>                             width: 300, left: 20, top: 20, right: 20,
> bottom: 10
>                         }
>                     };
>
>                     if (donutChartData.getNumberOfRows() > 1) {
>                         var donutChart = new
> google.visualization.PieChart(document.getElementById('programmatic_DonutChart'));
>                         donutChart.draw(donutChartData, options);
>                     }
>                     else {
>
> document.getElementById('programmatic_DonutChart').innerHTML = "No data to
> display!";
>                     }
>                 },
>                 error: function (data) {
>                     if ($("meta[name=debug]").attr("content") == "true") {
>                         //Full Error when debugging
>                         var errDoc = window.open();
>                         errDoc.document.write(data.responseText);
>                         errDoc.document.close();
>                     }
>                     else {
>                         // generic error message for production use
>                         alert("An unexpected error occurred.");
>                     } return false;
>                 }
>             });
>             return false;
>         }
>
> //Web Method
>
> [WebMethod]
>         public static string GetDonutChartData(string siteURL, string
> chartType)
> {
> string jsonData = "{'cols':
> [{'id':'','label':'Topping','pattern':'','type':'string'},"+
>         "{'id':'','label':'Slices','pattern':'','type':'number'}"+
>       "],'rows':
> [{'c':[{'v':'Mushrooms','f':null},{'v':3,'f':null}]},{'c':[{'v':'Onions','f':null},{'v':1,'f':null}]},{'c':[{'v':'Olives','f':null},{'v':1,'f':null}]},{'c':[{'v':'Zucchini','f':null},{'v':1,'f':null}]},"+
>         "{'c':[{'v':'Pepperoni','f':null},{'v':2,'f':null}]}]}";
>             //return list;
>             return jsonData;
> }
>
> //Error Message:
>
> Uncaught Error: Invalid JSON string: 'cols':
> [{'id':'','label':'Topping','pattern':'','type':'string'},{'id':'','label':'Slices','pattern':'','type':'number'}],'rows':
> [{'c':[{'v':'Mushrooms','f':null},{'v':3,'f':null}]},{'c':[{'v':'Onions','f':null},{'v':1,'f':null}]},{'c':[{'v':'Olives','f':null},{'v':1,'f':null}]},{'c':[{'v':'Zucchini','f':null},{'v':1,'f':null}]},{'c':[{'v':'Pepperoni','f':null},{'v':2,'f':null}]}]
>
>
> Please help!!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Visualization API" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to
> [email protected].
> Visit this group at
> https://groups.google.com/group/google-visualization-api.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/google-visualization-api/b5bcf61f-c75e-47a9-a906-bcc3a69d0417%40googlegroups.com
> <https://groups.google.com/d/msgid/google-visualization-api/b5bcf61f-c75e-47a9-a906-bcc3a69d0417%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
-- 

*[image: unnamed.gif]• Sergey Grabkovsky• Software Engineer• Google, Inc•
[email protected] <[email protected]>*

-- 
You received this message because you are subscribed to the Google Groups 
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-visualization-api.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-visualization-api/CAEwwup4TYCFZpLacLqbMa%2BG7BYG5Y9um6sik31MKHFZyU4oVhA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to