Describes common attributes and events of mschart.
Describes common attributes and events of mschart.
Mschart element composition
The most common attributes include
Chartareas: adds multiple drawing areas. Each drawing area contains independent chart groups and data sources. It is used when multiple chart types are incompatible in one drawing area.
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
Title: Axis title
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.
Legends: a legend.
Palette: Specifies the chart appearance.
Series: the most important attribute. A chart set is the final set of pie charts, bar charts, line charts, and point charts. Multiple compatible types can be placed in one drawing area, form a composite graph.
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)
Chartarea: name of the drawing area to which the chart belongs
Charttype: Chart type (such as column, pie, line, and point)
Legend: name of the legend used by the chart
Titles: Title set.
Width: the width of mschart.
Height: the height of mschart.
Common events:
Series1.points. databind ()
Bind a data point set. If you want to add charts of different data sources to a chart area (chartarea) of an mschart control, use this method to bind the data point set. You can bind the values of specified fields in the table to the specified coordinate axis.
Mschart1.databind ()
Bind a data source to the entire mschart. All charts in this mschart can use this data source as the statistical source.
<asp:Chart ID="Chart1" runat="server"><Series><asp:Series Name="Series1"></asp:Series></Series><ChartAreas><asp:ChartArea Name="ChartArea1"></asp:ChartArea></ChartAreas></asp:Chart>
This section describes the line chart, pie chart, and column chart of mschart.
If these three types of data are implemented using mschart, it is difficult for us to bind data, because we usually use dynamic data,
Microsoft instances basically write data on pages, and there is little information on the Internet, so you can only practice it on your own.
First, we will introduce the data binding methods of several mscharts,
The first and most popular
Chart1.datasource = getdata. getchartdata ();
Chart1.series ["chartarea1"]. xvaluemember = "home ";
Chart1.series ["chartarea1"]. yvaluemembers = "num1 ";
The second method is to bind data in the form of a list. Here we use the Variable list instead. Some variables are The names corresponding to the object class, and of course they also correspond to database fields.
Chart1.databindtable (list, "home ");
"Home" is the X axis Coordinate
Third, home group, time x axis coordinate, num1 Y axis Coordinate
Chart1.databindcrosstable (list, "home", "time", "num1", "label = num1, tooltip = num1 ");
Third, line chart binding method
Chart1.series [0]. Points. databind (list, "home", "num1", "label = num1, tooltip = num1 ");
Fourth, line chart binding method
Code
Chart1.databindcrosstable (list, "home", "time", "num1", "label = num1, tooltip = num1 ");
// Draw a line
Markerstyle marker = markerstyle. Square;
Foreach (Series Ser in chart1.series)
{
Ser. shadowoffset = 1;
Ser. borderwidth = 2;
Ser. charttype = seriescharttype. line;
Ser. markersize = 12;
Ser. markerstyle = marker;
Ser. markerbordercolor = color. fromargb (64, 64, 64 );
Ser. font = new font ("trebuchet ms", 8, fontstyle. Regular );
Marker ++;
}
Category 5:
Chart1.series ["Series1"]. Points. databindxy (list, "home", list, "num1 ");
Column chart under mschart
// Whether to enable 3D display chart1.chartareas [0]. area3dstyle. enable3d = true; // display type, which can be a column line, chart1.series [0]. charttype = seriescharttype. line; // draw as 3D cylinderchart1.series [0] ["drawingstyle"] = "Cylinder "; // For the pixels, see chart1.series [0] ["pointwidth"] = "0.8"; // whether to display the value chart1.series [0]. isvalueshownaslabel = true; // the X axis data display interval chart1.chartareas [0]. axisx. interval = 1; // Cartesian coordinate display, chart1.chartareas [0]. area3dstyle. isrightangleaxes = false; // whether to cluster chart1.chartareas [0]. area3dstyle. isclustered = false; // rotate the X axis angle chart1.chartareas [0]. area3dstyle. inclination = 40; // rotate the Y axis angle chart1.chartareas [0]. area3dstyle. rotation = 20; foreach (Series Ser in chart1.series) {// Bar Width ser ["pixelpointwidth"] = "40 "; // pixel depth ser ["pixelpointdepth"] = "80"; // pixel gap depth ser ["pixelpointgapdepth"] = "10 ";}
These attributes are the attributes for setting the appearance style of mschart. You can try to modify them,
Of course, the main thing is to bind data. Therefore, when calling these attributes, you must first bind data using several binding methods described above.
Some attributes may expire in 3D mode or in 2D mode, which is normal,
:
Line chart:
Properties are the same as above .. some properties will be invalid under the line chart,
:
Pie chart:
Ilist <chartmodel> List = getdata. getchartdatalistbypie (); // numerical display percentage form chart1.series ["Series1"]. label = "# percent {p}"; chart1.series ["Series1"]. points. databind (list, "home", "num1", "legendtext = home, yvalues = num1, tooltip = num1"); chart1.series ["Series1"]. charttype = system. web. UI. datavisualization. charting. seriescharttype. pie; chart1.series ["Series1"]. tooltip = "# legendtext: # Val {c} million"; chart1.chartareas ["chartarea1"]. area3dstyle. enable3d = true;
The main character here is chart1.series ["Series1"]. points. databind (list, "home", "num1", "legendtext = home, yvalues = num1, tooltip = num1"); legendtext took me a long time. this is shown on the right. It is not displayed at the beginning and is not uniform yet. legend is actually the description displayed on the right, but some people who have done it will find that there is still a line chart in the column chart. If a <lengend> </lengend> label is specified on the page, one more is displayed, therefore, you need to write the code chart1.series when executing the binding. clear (); mschart set the line chart node Style
Chart1.series ["Series1"]. markerstyle = markerstyle. circle; // set the dot tag style (this is a dot) chart1.series ["Series1"]. markersize = 8; // set the line node size
Set the cancel axis margin chart1.chartareas ["chartarea1"]. axisx. ismarginvisible = false;
Set the node to a hollow dot chart1.series ["Series1"]. markerstyle = markerstyle. Circle; // set the dot flag style (this is a dot)
Chart1.series ["Series1"]. markercolor = color. White;
Chart1.series ["Series1"]. bordercolor = color. Red;
Chart1.series ["Series1"]. borderwidth = 1;
Chart1.series ["Series1"]. markersize = 5; // set the line node size and place the cursor over the node. The automatic prompt function chart1.series ["Series1"]. tooltip = "number of articles # Val"; // # VAL--Y axis array to: http://www.cnblogs.com/xiaogangqq123/archive/2010/06/24/1764282.html