c# - If any possibility connects database in amcharts (pie Chart) in asp.net? -
<---- below code used 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 * chartpie id= userid + "'", con); con.open(); sqlcommand cmd = new sqlcommand("select * chartpie 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 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 value database?
modify script this. send ajax
request asp.net page
, assign result amchars dataprovider.
<script type="text/javascript"> $(document).ready(function () { $.ajax({ type: "post", contenttype: "application/json; charset=utf-8", url: "piechart.aspx/chartuser", data: "{userid : '123'}", datatype: "json", success: function (data) { amcharts.makechart("chartdiv", { "type": "pie", "theme": "none", "legend": { "markertype": "circle", "position": "right", "marginright": 80, "automargins": false }, "dataprovider": [data.chart], "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' }] } }); }, error: function (result) { alert("error"); } }); }); </script>
Comments
Post a Comment