ASP.NET Chart Control Free Control

The chart control was introduced in .NET3.5, which can support both Web and WinForm. Because it is rarely used in normal times, I have not played and have nothing to do. After a simple study, I feel that the function is really powerful. Basically It can meet the application of various charts. I only study things that feel so useful. It's really out of date. Haha, I think many people have already played it. Here is a review for everyone, and the masters bypass it.

Install MSChart

Since it was launched together with .NET3.5, it can only be used in the latest development environment and requires the development environment of .Net 3.5 Sp1 and VS 2008.

Control download link: Microsoft Chart Controls for Microsoft .NET Framework 3.5

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

According to the above address, download and install it.

You can also download here http://www.21kaiyun.com/pp.aspx

Use MSChart

After installation, we can use MSChart.

1. Main attributes:

 

Annotations--graphic annotation collection, ChartAreas--chart area collection, Legends--legend collection, Series--chart sequence collection (ie, chart data object collection), Titles--icon title collection.

(1) Annotations: It is a collection of some annotation objects for graphics. The so-called annotation objects are similar to the detailed or annotated description of a certain point. There can be multiple annotation objects on a graph, and more than ten types of annotation objects can be added, including common arrows, clouds, rectangles, pictures, etc. annotation symbols. Through the properties of each annotation object, you can easily set the annotation object Common attributes such as placement, color, size, and style of text content.

(2) ChartAreas: It is the drawing area of ​​a chart, such as displaying multiple drawings in one chart. The chart control does not limit how many drawing areas you add, you can add them according to your needs. For each drawing area, you can set its own properties, such as: X, Y axis properties, background, etc.

(3) Legends: It is a collection of legends, that is, the meaning of each line or color in the annotation graphics. Similarly, a picture can also contain multiple legend descriptions.

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

(5)Titles: The title collection of the icon. It is not difficult to understand, that is, the title configuration of the chart. Multiple titles can also be added.

 

Other attributes:

AlignmentOrientation: The alignment direction of the chart area, which defines the alignment between the two drawing areas.

AlignmentStyle: The alignment type of the chart area, which defines the elements used to align the charts.

AlignWithChartArea: Refer to the name of the drawing area to be aligned.

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, the value ranges from 0-100)

Width: the width of the chart in the drawing area (percentage, the value ranges from 0-100)

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

Position: The position attribute of the drawing area, same as InnerPlotPosition.

Name: The name of the drawing area.

Axis: coordinate axis collection

TitleAlignment: axis title alignment

Interval: the size of the axis scale interval

IntervalOffset: the size of the axis scale offset

MinorGrid: secondary auxiliary line

MinorTickMark: Minor tick mark

MajorGrid: the main auxiliary line

MajorTickMark: Major tick mark

DataSourceID: The data source of MSChart.

Palette: Definition of chart appearance.

IsValueShownAsLabel: Whether to display the data point label, if true, display each data value in the chart

Label: Data point label text

LabelFormat: Data point label text format

LabelAngle: label font angle

Name: Chart name

Points: data point collection

XValueType: horizontal axis type

YValueType: ordinate axis type

XValueMember: The data source bound to the abscissa (if the data source is Table, fill in the name of the field to be displayed on the abscissa)

YValueMembers: the data source bound to the ordinate (if the data source is Table, fill in the name of the field to be displayed on the ordinate, there can be two ordinates)

ChartType: chart type (column, pie, line, dot, etc.)

width: The width of MSChart.

height: The height of MSChart.

2. Data binding method

MSChart provides a variety of ways to bind data:

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绑定:

代码
            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绑定:

代码
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:

代码
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 Microsoft's DEMO research.




The fly in the ointment is that MSChart can only be used in .NET3.5.

21st Century Kaiyun.com’s Ziwei Doushu constellation online arrangement system is drawn with this control, and I dare not enjoy the good things exclusively.

 

Guess you like

Origin blog.csdn.net/jinzhengquanqq/article/details/5878303