FusionCharts simple demo for (html + js, APS. NET Webform, MVC ),

Source: Internet
Author: User

FusionCharts simple demo for (html + js, APS. NET Webform, MVC ),

It should be no stranger to FusionCharts to do GIS or other internal data statistics projects. It is easy to use and there is no need to say anything, but sometimes the framework is different and the implementation is slightly different.

Reference dll call FusionCharts class static method RenderChartHTML returns html bound to the data control more in line with webform;

Using the JS Code new FusionCharts object, the setDataXML or setDataURL method of the called object is more in line with MVC

 

1. HTML + JS

<! -- Html --> 

2. ASP. NET Webform

<! ------------- Aspx --------------> <form id = "form1" runat = "server"> <div> <table id = "tbl" border = "0" cellpadding = "0" cellspacing =" 0 "> <tr> <td> <asp: dropDownList ID = "DropDownList1" runat = "server" AutoPostBack = "true"> <asp: ListItem Text = "Bar Chart" Value = "0"> </asp: listItem> <asp: ListItem Text = "Pie Chart" Value = "1"> </asp: ListItem> </asp: dropDownList> </td> </tr> <td> <asp: Panel ID = "Panel1" runat = "server"> </ Asp: Panel> </td> </tr> </table> </div> </form> <! ------------- Code behind --------------> protected void Page_Load (object sender, EventArgs e) {Panel1.Controls. clear (); Dictionary <string, int> data = new Dictionary <string, int> () {"banana", 12}, {"orange", 55 }, {"apple", 23 },{ "Ginseng fruit", 20 }}; Panel1.Controls. add (ShowNewChart (data, DropDownList1.SelectedValue, "quantity "));} /// <summary> /// bind the graphic data /// </summary> /// <param name = "dic"> data </param> /// <param name = "Type"> Graphic Type </param> /// <param name = "yAxisName"> bar chart title </param> /// <returns> </returns> private LiteralControl ShowNewChart (Dictionary <string, int> dic, string Type, string yAxisName) {StringBuilder sb = new StringBuilder (); sb. append ("<chart rotateYAxisName = '0' baseFont = ''baseFontSize = '12' caption ='' xAxisName = ''yaxisname =' "+ yAxisName +" 'bgcolor =' 'ffffff' bgalpha = '000000' showValues = '1' formatNumberScale = '0' showBorder = '0'> "); foreach (string key in dic. keys) {sb. appendFormat ("<set label = '{0}' value = '{1}'/>", key, dic [key]);} sb. appendFormat ("</chart>"); string types = ""; if (Type = "1 ") {// pie chart swf path types = "package/FusionCharts/Charts/Pie3D.swf";} else if (Type = "0 ") {// bar chart types = "package/FusionCharts/Charts/2Column3D.swf";} return new LiteralControl (FusionCharts. renderChartHTML (types, "", sb. toString (), "chart1", "650", "250", false, false ));}

3. ASP. NET MVC

// -------------------------- View ------------------------------------ <script src = "@ Url. Content ("~ /Package/FusionCharts/Charts/FusionCharts. js ")" type = "text/javascript"> </script> <script type = "text/javascript" >$ (function () {initChars ('@ Url. content ("~ /Package/FusionCharts/Charts/2Column3D.swf ") '); BindslMapTypeChange ();}) // initialize the chart function initChars (fusionChartsPath) {var chart = new FusionCharts (fusionChartsPath, "ChartId", "600", "350"); chart. setDataXML ("@ (new MvcHtmlString (ViewData. model) "); chart. render ("showData");} // bind chart type selection button event function BindslMapTypeChange () {$ ('# slmaptype '). change (function () {if ($ (this ). val () = "1") {initChar S ('@ Url. Content ("~ /Package/FusionCharts/Charts/2Column3D.swf ") ');} else {initChars (' @ Url. Content ("~ /Package/FusionCharts/Charts/Pie3D.swf ")');}})} </script> <table border = "0" cellpadding = "0" cellspacing = "0"> <tr> <td> image type: <select id = "slMapType"> <option value = "1"> column chart </option> <option value = "2"> pie chart </option> </select> </ td> </tr> <td id = "showData"> </td> </tr> </table> // -------------------------- action -------------------------------- public ActionResult Index () {Dictionary <string, int> data = new Dictionary <string, int> () {"banana", 12 },{ "orange", 55 },{ "apple ", 23 },{ "Ginseng fruit", 20 }}; ViewData. model = GetChartXml (data, "fruit quantity"); return View ();} /// <summary> /// bind the graphic data /// </summary> /// <param name = "dic"> data </param> /// <param name = "Type"> Graphic Type </param> /// <param name = "yAxisName"> bar chart title </param> /// <returns> </returns> private string GetChartXml (Dictionary <string, int> dic, string yAxisName) {StringBuilder sb = new StringBuilder (); sb. append ("<chart rotateYAxisName = '0' baseFont = ''baseFontSize = '12' caption ='' xAxisName = ''yaxisname =' "+ yAxisName +" 'bgcolor =' 'ffffff' bgalpha = '000000' showValues = '1' formatNumberScale = '0' showBorder = '0'> "); foreach (string key in dic. keys) {sb. appendFormat ("<set name = '{0}' value = '{1}'/>", key, dic [key]);} sb. appendFormat ("</chart>"); return sb. toString ();}

  

Source code: http://files.cnblogs.com/NotAnEmpty/FusionCharts.rar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.