In the previous article, I introduced mschart, a chart control under winforms. Although mschart also provides us with chart support on ASP.net, the actual use process is not satisfactory, so it happened that some people wanted to use flash charts such as funsioncharts to display them on pig Bajie. So it took some time to learn. This article is to record some usage problems of funsioncharts.
The following is what we will introduce:
1. Introduction to chart selection under Asp.net
2. Problems Encountered during funsioncharts development and solutions.
1. Introduction to chart selection under Asp.net
Compared to winforms, data can only be displayed through controls, there are many more options for displaying charts on ASP.net. Below I will briefly introduce several options, it mainly focuses on its advantages and disadvantages:
1,Mschart, a chart control encapsulated by Microsoft, something of Microsoft's own, and some other chart controls, but mschart is relatively better.
Advantages:HeavyweightIt has powerful functions and covers various charts required by all walks of life. It has rich documents and instances and has good results.
Disadvantage: it is difficult to use and requires various configurations. If a configuration error occurs, it cannot be displayed,The principle is to generate an image based on the configured chart type and input data, and then display the corresponding image on the page.The application is narrow and cannot be used in a large number of pages. It is troublesome to use it in Asp.net.
The effect is as follows:
2,All kinds of JS charts. When it comes to JS charts, the most powerful is the icon library provided by Google (maybe I don't know). You just need to introduce the corresponding JS Library to the page, then input the corresponding data to draw on the page.
Advantages:LightweightIt has powerful functions and rich chart resources. It is drawn through JS and has a general effect. Therefore, it runs fast and has a wide range of applications.
Disadvantages: fewer documents and instances (except for some JS chart documents dedicated to JS chart libraries such as Google) require a certain JS Foundation for use.
As follows:
3,All kinds of Flash charts. This is the chart type described in this article. It mainly relies on JS or. NET class library to output XML on the page, while Flash reads XML to present the corresponding data on the page.
Advantages: Medium magnitude, powerful functions, brilliant effects, easy to use, simple XML basics.
Disadvantages: billing, no more than the above two types of charts.
As follows:
The above is a common chart type on ASP.net. You can select a chart based on your actual needs.
Ii. Issues encountered during funsioncharts development and solutions.
I was surprised to use funsioncharts. I was attracted by the fact that I had to use funsioncharts to achieve some brilliant chart effects when I went around to watch other people's tasks, at that time, corresponding charts were also needed for the project.
Funsioncharts is one of the many flash charts. It has nearly 40 built-in flash charts. For details, go to the blog of my workshop, I will not go into details here.
The following describes my problems:
1. Select chart output mode
In fact, the chart display of funsioncharts still relies on JS to display the data required by the chart into flash. In order to facilitate the development of Asp.net, funsioncharts encapsulates a DLL used by Asp.net to output the Js for displaying the chart to the page. For details, refer to the official example of funsioncharts.Code(ArticleAttached ).
For better user experience, for example, you can directly call funsioncharts through JS during Ajax interaction. the corresponding methods in JS files. for enterprise-level development or Asp.net-based development, you can call the DLL method encapsulated by funsioncharts.
Using funsioncharts in Asp.net is very simple. You only need to splice strings according to the XML rules, and then output the results using the formulated method. The following is a sample code:
Sqlcommand cmd = new sqlcommand (); sqldatareader reader = NULL; stringbuilder sbages = new stringbuilder (); List <chartclass> List = new list <chartclass> (); try {sqlconnection con = new sqlconnection (system. configuration. configurationmanager. connectionstrings ["connectionstring"]. connectionstring); con. open (); cmd. connection = con; cmd. commandtext = "sp_crc_demo_rpt_age"; cmd. commandtype = commandtype. s Toredprocedure; cmd. parameters. add ("@ zonename", sqldbtype. nvarchar, 64 ). value = uczonelist1.selectedvalue; cmd. parameters. add ("@ beginyear", sqldbtype. INT ). value = convert. toint32 (txtbeginyear. text. trim (); cmd. parameters. add ("@ endyear", sqldbtype. INT ). value = convert. toint32 (txtendyear. text. trim (); reader = cmd. executereader (); While (reader. read () {chartclass cc = new chartclass (); CC. catname = Reader ["age group"] as string; CC. count = convert. toint32 (Reader ["Total"]); list. add (CC);} sbages. append ("<chart caption = 'patient age comparison fig 'formatnumberscale = '0' xaxisname = 'Age group 'yaxisname = 'number of diseased number'>"); For (INT I = 0; I <list. count; I ++) {sbages. appendformat ("<set label = '{0}' value = '{1}'/>", list [I]. catname, list [I]. count. tostring ();} // Add the style to start sbages. append ("<styles>"); sbages. append ("<definition>"); sbages. AP Pend ("<style name = 'titlefont' type = 'font' size = '14'/>"); sbages. append ("<style name = 'axisfont' type = 'font' size = '12'/>"); sbages. append ("</definition>"); sbages. append ("<Application>"); sbages. append ("<apply toobject = 'caption 'styles = 'titlefont '/>"); sbages. append ("<apply toobject = 'axisname' styles = 'axisfont'/>"); sbages. append ("<apply toobject = 'axisname' styles = 'axisfont'/>"); sbages. append ("<Apply toobject = 'datalabels' styles = 'axisfont'/>"); sbages. append ("</Application>"); sbages. append ("</styles>"); sbages. append ("</chart>"); If (! Ispostback) {ltagechart. TEXT = fusioncharts. rendercharthtml ("funsioncharts/column3d.swf", "", sbages. tostring (), "yearagechart", "600", "250", false, false); ltagecharttable. TEXT = fusioncharts. rendercharthtml ("funsioncharts/bar2d.swf", "", sbages. tostring (), "yearagecharttable", "600", "250", false, false);} else {ltagechart. TEXT = fusioncharts. renderchart ("funsioncharts/column3d.swf", "", sbages. tostring (), "yearagechart", "600", "250", false, false); ltagecharttable. TEXT = fusioncharts. renderchart ("funsioncharts/bar2d.swf", "", sbages. tostring (), "yearagecharttable", "600", "250", false, false );}}
The main steps of this Code:
1. obtain data from the database according to the conditions.
2. splice the data into the specified XML. For the XML format, see the official API: click "I.
3. Use fusioncharts. renderchart to output the corresponding JS script.
The final output JS is as follows:
VaR chart_yearagecharttable = new fusioncharts ("funsioncharts/bar2d.swf", "yearagecharttable", "600", "250", "0", "0", "", "noscale ", "EN "); chart_yearagecharttable.setdataxml ("<chart caption = 'patient age comparison fig 'formatnumberscale = '0' xaxisname = 'Age group 'yaxisname = 'number of diseased number'> <set label = '0-10' Value = '0'/> <set label = '11-20 'value = '000000'/> <set label = '21-30' value = '000000'/> <set label = '31-40' value = '000000'/> <set label = '41-50' value = '000000'/> <set label = '61 + 'value = '75'/> <styles> <definition> <style name = 'titlefont' type = 'font' size = '14'/> <style name = 'axisfont' type =' font 'size = '12'/> </definition> <Application> <apply toobject = 'caption 'styles = 'titlefont '/> <apply toobject = 'xaxisname' styles =' axisfont '/> <apply toobject = 'axisname' styles = 'axisfont'/> <apply toobject = 'datalabels' styles = 'axisfont'/> </Application> </styles> </chart> "); chart_yearagecharttable.render ("yearagecharttablediv ");
As follows:
Ii. Customize the style of funsioncharts
In the figure above, we can find that the Chinese character sections [patient age comparison chart] and [number of diseased users] are relatively small, and the results are very poor in actual use, therefore, you need to change the font style.
There is a special <styles> label in the XML data of funsioncharts to define the style of the flash display icon, which is mainly divided into two steps:
1. Define a style, add <definition> under <styles>, and then define the desired style.
2. Apply a style, add <Application> under <styles>, and apply the defined style to the chart, note that the objects referenced in the application style must be existing objects in the chart, and these objects have their own names. If you do not know them, you can view the API.
The specific application code is as follows:
// Add the style to start sbages. append ("<styles>"); sbages. append ("<definition>"); sbages. append ("<style name = 'titlefont' type = 'font' size = '14'/>"); sbages. append ("<style name = 'axisfont' type = 'font' size = '12'/>"); sbages. append ("</definition>"); sbages. append ("<Application>"); sbages. append ("<apply toobject = 'caption 'styles = 'titlefont '/>"); sbages. append ("<apply toobject = 'axisname' styles = 'axisfont'/>"); sbages. append ("<apply toobject = 'axisname' styles = 'axisfont'/>"); sbages. append ("<apply toobject = 'datalabels' styles = 'axisfont'/>"); sbages. append ("</Application>"); sbages. append ("</styles> ");
After this reference, the output chart results will be immediately displayed, and the title and corresponding text will become larger, such:
Of course, funsioncharts also has many powerful functions, which can be used to define a lot of beautiful style effects.ProgramAnd so on. You need to check the API by yourself. I have not studied it further.
Download the official sample program: Click here to download
In other words, if you think this article is useful to you or you think it is useful, move the cursor over [recommendation] and click it for me. Thank you very much!
Records of various problems encountered during the project process
Editor:
FCKeditor related knowledge and various common usage Problems
FCKeditor custom upload path Configuration
Use FCKeditor to generate static paging html
Chart:
Tips on mschart
Good chart selection on ASP.net-funsioncharts
Orm:
Some minor issues with using nhib.pdf to configure object entities
About Nhibernate query Encapsulation
Deployment:
Problems related to project deployment-IIS
The tangled problems during project deployment-sqlserver
Tools:
. Net tool library frequently used for development