Hello Zoomocharts. We're getting ready to purchase Zoomcharts for our organzation, but we're having problems getting your PieChart populated from a jQuery call to a WebMethod, which resides in our ASPX page. The Web method fires, but the PieChart remains blank (we tried both IE and Chrome). I have to assume it's a knowledge issue - not a product issue. Any assistance would be greatly appreciated.
//From our HTML Page
<div id="chartContainer" style="width:300px;height:300px"></div>
<script type="text/javascript">
var t = new PieChart({
id: "testChart",
container: document.getElementById("chartContainer"),
area: { height: 350 },
data: { dataFunction: asyncServerCall }
});
function sliceStyle(slice, data) {
slice.insideLabel.text = slice.percent.toFixed(2) + "%";
slice.label.text = data.name;
}
function infoContents(data) {
return "<h3>" + data.name + '</h3><a class="DVSL-info">Visits:<b>' + data.value + "</b></a>";
}
function asyncServerCall(pieId, limit, offset, successCallback, errorCallback) {
var myErrorCallback = function () {
if (window.console) console.log("There was an error while requesting data for pie '" + pieId + "'");
errorCallback();
};
var result = jQuery.ajax({
url: 'AttributeAnalytics.aspx/GetChartData',
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: successCallback,
error: myErrorCallback
});
}
</script>
//From out ASPX page
public class ChartValue
{
public int value { get; set; }
public string name { get; set; }
public string id { get; set; }
}
public class ChartResponse
{
public string id {get; set;}
public List<ChartValue> values = new List<ChartValue>();
}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static ChartResponse GetChartData()
{
ChartResponse resp = new ChartResponse();
resp.id = "gender";
List<ChartValue> values = new List<ChartValue>();
ChartValue cv = new ChartValue();
cv.name="Male";
cv.value = 8000;
cv.id = "1a";
resp.values.Add(cv);
cv = new ChartValue();
cv.name="Female";
cv.value = 4000;
cv.id = "1b";
resp.values.Add(cv);
// We tried returning some sample JSON as a string, instead of a serialized JSon object. This didn't work either
//string serializedResult = "{\"values\": [{ \"value\": \"200\", \"name\": \"male\", \"id\": \"s1\" }, { \"value\": \"150\", \"name\": \"female\", \"id\": \"s2\"}]}";
// return serializedResult ;
return resp;
}