Install MSChart
Because IS and. NET3.5, so it can only be used in the most recent development environment, with the. Net 3.5 Sp1 and VS 2008 development environment.
Control Download Address: Microsoft Chart control Microsoft. NET Framework 3.5 (Microsoft Chart Controls for Microsoft. NET Framework 3.5)
The Demo:http://code.msdn.microsoft.com/mschart provided by Microsoft
According to the above address, download the installation is OK.
using MSChart
Once installed, we can use the MSChart.
1. Main attributes:
annotations--Graphical annotation collection, chartareas--chart area collection, legends--legend collection, series--chart collection (that is, a collection of chart data Objects), and a collection of titles for titles--icons.
(1) Annotations: is a collection of some annotation objects of a graph, the so-called annotation object, similar to the detailed or annotated description of a point. You can have multiple annotation objects on a graph, you can add more than 10 graphic styles of annotation objects, including common arrows, clouds, moment lines, pictures and so on annotation symbols, through the properties of each annotation object, you can easily set the note object placement, rendering color, size, text content style and other common properties.
(2) Chartareas: is a plot area for a chart, such as displaying multiple drawings in a picture. Chart controls do not limit how many drawing areas you add, and you can add them to your needs. For each drawing area, you can set individual properties, such as X,y axis properties, backgrounds, and so on.
(3) Legends: is a collection of legends, that is, the meaning of each line or color in the callout graph, and also a picture can contain multiple legend descriptions.
(4) Series: is a collection of table data objects, which should be said to be a key part of MSChart. That is, the actual plot data area, the actual rendering of the shape of the graph, which is composed of each of the charts, you can add multiple charts to the collection, each chart can have its own drawing shape, style, independent data and so on.
(5) titles: A collection of the titles of icons, it is not difficult to understand, is the chart title configuration, can also add multiple headings.
Additional properties:
Alignmentorientation: Chart area alignment, which defines the alignment between two drawing areas.
Alignmentstyle: The chart area alignment type that defines the elements that are used between diagrams.
Alignwithchartarea: The name of the drawing area to which to reference the alignment.
Innerplotposition: The position attribute of the chart within the plot area.
Auto: Whether to align automatically.
Height: The level of the chart within the plot area (percentage, value in 0-100)
Width: How wide the chart is within the plot area (percentage, value in 0-100)
X,y: Chart in the upper-left corner of the plot area
Position: Plot area position attribute, same as innerplotposition.
Name: The plot area names.
Axis: Collection of axes
Titlealignment: Axis Title Alignment
Interval: Axis tick spacing size
Intervaloffset: Axis tick offset size
Minorgrid: Secondary Guides
MinorTickMark: Minor tick marks
Majorgrid: Main Auxiliary line
MajorTickMark: Major tick marks
The Datasourceid:mschart data source.
Palette: chart appearance definition.
Isvalueshownaslabel: Whether to display the data point label, if true, to display each data value in the chart
Labelformat: Data point label text format
Labelangle: Label Font angle
Name: Chart names
Points: Collection of data points
Xvaluetype: Horizontal axis type
Yvaluetype: Ordinate axis type
Xvaluemember: The horizontal coordinate data source (if the data source is a table, fill the horizontal axis the field name to display)
Yvaluemembers: Ordinate bound data source (if the data source is table, fill in the field name to be displayed by ordinate, can have two ordinate)
ChartType: Chart type (columnar, pie, linear, dotted, etc.)
The width of the width:mschart.
The height of the height: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 binding: 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: 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;
}