Hi @RAVI
After my modifications to your code, I implemented your needs. This is full of complex data type conversions.
1.Open RouteConfig.cs
Modify the code:
public static class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
var settings = new FriendlyUrlSettings();
settings.AutoRedirectMode = RedirectMode.Off;
routes.EnableFriendlyUrls(settings);
}
}
2.Modify the front-end code
<html>
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript" src="Scripts/jquery-3.4.1.js"></script>
<script type="text/javascript">
google.charts.load('current', { 'packages': ['corechart'] });
google.charts.setOnLoadCallback(drawChart);
$(function () {
$.ajax({
type: "Post",
url: "Default2.aspx.aspx/GetChartData",
contentType: "application/json;charset=utf-8",
dataType: "json",
success:
function (response) {
drawChart(response.d);
},
});
})
function drawChart(dataValues) {
var data = new google.visualization.DataTable();
var list = [];
data.addColumn('string', 'Column Name');
data.addColumn('number', 'Column Value');
dataValues.forEach((item) => {
var value = [item.countryname, item.total];
list.push(value);
});
data.addRows(list);
var options = {
'title': 'Show Google Chart in Asp.net',
'width': 400,
'height': 300
};
var chart = new google.visualization.PieChart(document.getElementById('chartdiv'));
chart.draw(data, options);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="chartdiv" style="width: 600px; height: 350px;">
</div>
</form>
</body>
</html>
Output:
Main problem: The parameter of data.addrows is list[list].
Best regards,
Qi You
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.