<---- This below code used for PieChart.aspx.cs ---->
protected void Page_Load(object sender, EventArgs e)
{
}
public chart ChartUser(string UserId)
{
chart c = new chart();
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=emp;Integrated Security=True");
// SqlDataAdapter da = new SqlDataAdapter("select * from ChartPie where id= UserId + "'", con);
con.Open();
SqlCommand cmd = new SqlCommand("select * from ChartPie where id='" + UserId + "'", con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
c.UserId = dr["UserId"].ToString();
c.Language = dr["Language"].ToString();
c.percentage = dr["percentage"].ToString();
}
return c;
}
public class chart
{
public string UserId { get; set; }
public string Language { get; set; }
public string percentage { get; set; }
}
}
<---- give below code used for script file ----->
var chart = AmCharts.makeChart("chartdiv", {
"type": "pie",
"theme": "none",
"legend": {
"markerType": "circle",
"position": "right",
"marginRight": 80,
"autoMargins": false
},
"dataProvider": [{
"Language": "Tamil",
"percentage": 50
}, {
"Language": "English",
"percentage": 40
}, {
"Language": "Hindi",
"percentage": 30
}],
"valueField": "percentage",
"titleField": "Language",
colorField: "color",
"balloonText": "[[title]]<br><span style='font-size:14px'><b>[[value]]</b> ([[percents]]%)</span>",
"exportConfig": {
"menuTop": "0px",
"menuItems": [{
"icon": '/lib/3/images/export.png',
"format": 'png'
}]
}
});
Kindly tell me how can I get value from database?
Modify the script like this. Send the
Ajax
request to theasp.net page
and assign the result to theAmChars dataprovider.