0👍
I have fixed my issue
Here is the new server code:
<WebMethod()>
Public Shared Function GetChart() As List(Of Object)
Dim iData As New List(Of Integer)()
Dim sColor As New List(Of String)()
Dim sLabel As New List(Of String)()
Dim chartData As New List(Of Object)()
Dim objConn As New SqlConnection(ConfigurationManager.ConnectionStrings("conProcase").ToString)
objConn.Open()
Try
'... my db stuff
Do While objRdr.Read()
iData.Add(Convert.ToInt32(objRdr("iCount")))
sColor.Add([String].Format("#{0:X6}", New Random().Next(&H1000000)))
sLabel.Add(objRdr("Co_Desc"))
Loop
objRdr.Close()
Catch ex As Exception
Finally
If Not IsNothing(objConn) Then
objConn.Close()
objConn = Nothing
End If
End Try
chartData.Add(iData)
chartData.Add(sColor)
chartData.Add(sLabel)
Return chartData
End Function
The jquery side:
function LoadChart() {
var ctx = document.getElementById("chart-area").getContext('2d');
$.ajax({
type: "POST",
url: "_TempEntrada.aspx/GetChart",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (r) {
var sData =
{
labels: r.d[2] ,
datasets: [
{
backgroundColor: r.d[1],
data: r.d[0]
},
]
};
var config = {
type: 'doughnut',
data:sData,
options: {
responsive: true,
legend: {
position: 'top',
},
title: {
display: true,
text: 'Chart.js Doughnut Chart'
},
animation: {
animateScale: true,
animateRotate: true
}
}
};
var myDoughnutChart = new Chart(ctx, config);
},
failure: function (response) {
alert('There was an error.');
}
});
}
Source:stackexchange.com