ASP. NET Chart Control

Source: Internet
Author: User

. Net3.5 introduced the chart control, which can support both web and winform modes at the same time. Since it is rarely used at ordinary times, it has never been used, so it is easy to do it. After a simple study, I feel that the function is really powerful, basically, it can satisfy the application of various charts. I feel that this is a little outdated. Haha, I think many people have already played it. Here I will help you review it, expert bypass.

Install mschart

Since it was launched with. net3.5, it can only be used in the latest development environment. Net 3.5 SP1 and vs 2008 development environments are required.

Control: Microsoft chart control of Microsoft. NET Framework 3.5 (Microsoft chart controls for Microsoft. NET Framework 3.5)

Microsoft Demo: http://code.msdn.microsoft.com/mschart

Follow the above address to download and install it.

Use mschart

After installation, we can use mschart.

1. Main attributes:

Annotations-graph annotation set, chartareas-chart region set, legends-legend set, Series-chart sequence set (that is, chart data object set), titles-Icon title set.

(1)Annotations: A set of annotation objects for a graph. The so-called annotation object is similar to a detailed or annotated description of a vertex. A single image can have multiple annotation objects, and can add annotation objects of more than a dozen graphic styles, including common arrows, clouds, moments, images, and other annotation symbols, through the attributes of each annotation object, you can easily set the location, color, size, text content style, and other common attributes of the annotation object.

(2)Chartareas: Is the drawing area of a chart. For example, multiple charts are displayed in a graph. The chart control does not limit how many drawing areas you can add as needed. For each drawing area, you can set its own attributes, such as X, Y axis, and background.

(3)Legends: Is a collection of legends, indicating the meaning of each line or color in the image. Likewise, an image can contain multiple legends.

(4)Series: Is a collection of table data objects. It should be said to be a key part of mschart. That is, the actual drawing data area, the actual display of the graphic shape, which is composed of each chart in the set, you can add multiple charts to the set, each chart can have its own shape, style, and independent data.

(5)Titles: It is easy to understand the title set of an icon, that is, the title configuration of a chart. You can also add multiple titles.

Other attributes:

Alignmentorientation: alignmentorientation defines the alignment between two drawing areas.

Alignmentstyle: alignentstyle is an alignment type that defines the elements used between charts.

Alignwithchartarea: Specifies the name of the alignwithchartarea.

Innerplotposition: The position attribute of the chart in the drawing area.

Auto: whether to automatically align.

Height: the height of the chart in the drawing area (percentage, value range: 0-100)

Width: the width of the chart in the drawing area. The value ranges from 0 to 100)

X, Y: coordinates of the chart in the upper left corner of the drawing Area

Position: The position attribute of the drawing area, which is the same as innerplotposition.

Name: name of the drawing area.

Axis: Coordinate Axis set

Titlealignment: Axis title alignment

Interval

Intervaloffset: the offset of the Axis scale.

Minorgrid: Secondary guides

Minortickmark: secondary dial

Majorgrid: main guides

Majortickmark: Main dial

Performanceid: the data source of mschart.

Palette: Specifies the chart appearance.

Isvalueshownaslabel: whether to display the data point label. If it is true, each data value is displayed in the chart.

Labelformat: data point label text format

Labelangle: label font Angle

Name: Chart name

Points: data point set

Xvaluetype: X axis type

Yvaluetype: Y axis type

Xvaluemember: the data source bound to the X coordinate. (If the data source is table, enter the name of the field to be displayed)

Yvaluemembers: the data source bound to the Y coordinate. (If the data source is table, enter the name of the field to be displayed. The Y coordinate can have two values)

Charttype: Chart type (such as column, pie, line, and point)

Width: the width of mschart.

Height: the height of mschart.

2. Data Binding method

Mschart provides multiple data binding methods:

Array binding:

Double [] Yval = { 2 , 6 , 4 , 5 , 3 };
String [] Xval = { " Peter " , " Andrew " , " Julie " , " Mary " , " Dave " };
Chart1.series [ " Series 1 " ]. Points. databindxy (xval, yval );

Datareader binding:

Code

String Filenamestring =   This . Mappath ( " . " );
Filenamestring + =   " .. \... \ Data \ chartdata. MDB " ;
String Myconnectionstring =   " Provider = Microsoft. Jet. oledb.4.0; Data Source = "   + Filenamestring;
String Myselectquery = " Select name, sales from reps where regionid <3; " ;
Oledbconnection myconnection =   New Oledbconnection (myconnectionstring );
Oledbcommand mycommand =   New Oledbcommand (myselectquery, myconnection );
Mycommand. Connection. open ();
Oledbdatareader myreader = Mycommand. executereader (commandbehavior. closeconnection );
Chart1.series [ " Default " ]. Points. databindxy (myreader, " Name " , Myreader, " Sales " );
Myreader. Close ();
Myconnection. Close ();

Datatable binding:

Code

String Filenamestring =   This . Mappath ( " . " );
Filenamestring + =   " .. \... \ Data \ chartdata. MDB " ;
String Myconnectionstring =   " Provider = Microsoft. Jet. oledb.4.0; Data Source = "   + Filenamestring;
String Myselectquery = " Select name, sales from reps; " ;
Oledbconnection myconnection =   New Oledbconnection (myconnectionstring );
Oledbcommand mycommand =   New Oledbcommand (myselectquery, myconnection );
Mycommand. Connection. open ();
Oledbdatareader myreader = Mycommand. executereader (commandbehavior. closeconnection );
Chart1.databindtable (myreader, " Name " );
Myreader. Close ();
Myconnection. Close ();

Excel binding:

Code

String Filenamestring =   This . Mappath ( " . " );
Filenamestring + =   " .. \... \ Data \ exceldata.xls " ;
String Sconn =   " Provider = Microsoft. Jet. oledb.4.0; Data Source = "   +  
Filenamestring +   " ; Extended properties = \ " Excel 8.0 ; HDR = Yes \ "" ;
Oledbconnection myconnection =   New Oledbconnection (sconn );
Myconnection. open ();
Oledbcommand mycommand =   New Oledbcommand ( " Select * from [data1 $ A1: E25] " , Myconnection );
Oledbdatareader myreader = Mycommand. executereader (commandbehavior. closeconnection );
Chart1.databindtable (myreader, " Hour " );
Myreader. Close ();
Myconnection. Close ();
Foreach (Series Ser In Chart1.series)
{
Ser. shadowoffset =   1 ;
Ser. borderwidth =   3 ;
Ser. charttype = Seriescharttype. line;
}

 

There are other forms of data binding. You can download the demo from Microsoft.

In the US, mschart can only be used in. net3.5. You can see this in 2.0:

Http://www.cnblogs.com/gaoweipeng/archive/2009/04/18/1438821.html

 

 

Related Article

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.