Use the WinForm Chart control to make pie, columnar, line charts

Source: Internet
Author: User
Tags border color polyline

http://blog.csdn.net/dream2050csdn/article/details/53510340

There are a lot of properties for the chart control, and there are five properties that are used primarily in the chart area.
: Annotation collection (I don't know how to use it, but the configuration will appear in the icon area for something to say)
2.ChartAreas: chart Area properties, mainly set the background of the icon data, such as 3D or hide or show horizontal vertical axis intersection, block color display, etc.
3.Lengends: chart legend collection mainly set the chart side description of some things, this project is not used, but feel that the basic no use, there is nothing to add to the general, not to use the property
: Chart series properties, most of the settings in chart settings are here, to set the appearance of the data, data types (pie chart, line chart, tree chart, etc.)
Chart Title collection, used to set the title of the chart

To refer to this before using
Using System.Windows.Forms.DataVisualization.Charting;

This is the two sets of data that are added list<Int> TxData2 =New list<Int> () {2011, 2012, 2013, 2014, 2015, 2016}; List<int> tyData2 = new list< int> () {9, 6, 7, 4, 5, 4}; List<int> txData3 = new list< int> () {2012}; List<int> tyData3 = new list< int> () {7};        
Chart ct= new chart (); If you are a new chart, you need toAdd its title,series,chartareas properties//If you drag directly into the control you just need to adjust it in the control properties.//Title CT. Titles. ADD ("My Annual contract average price (yuan/trillion kwh)"); Background ct. Chartareas. ADD (New ChartArea () {Name ="CA1"}); Background Box CT. chartareas[0]. axes[0]. Majorgrid. Enabled =false; X-axis Grid CT. chartareas[0]. axes[1]. Majorgrid. Enabled = False; Y-Axis Grid ct. chartareas[0]. axes[0]. Majorgrid. LineDashStyle = Chartdashstyle. Dash; Grid type short horizontal line ct. chartareas[0]. axes[0]. Majorgrid. LineColor = Color. Gray; Ct. chartareas[0]. axes[0]. MajorTickMark. Enabled =false; Small Point CT on x-axis. chartareas[0]. axes[1]. MajorTickMark. Enabled = False; Ct. chartareas[0]. axes[1]. Isinterlaced = True; Display of staggered-band CT. chartareas[0]. axes[0]. LabelStyle. Format ="#年"; Set X-axis display style ct. chartareas[0]. axes[1]. Majorgrid. LineDashStyle = Chartdashstyle. Dash; Grid type short horizontal line ct. chartareas[0]. axes[1]. Majorgrid. LineColor = Color. Gray; Ct. chartareas[0]. axes[1]. Majorgrid. LineWidth =3; Chart data area with multiple overlapping loops to add CT. Series. ADD (New Series ()); Add a chart sequence//CT. series[0]. Xvaluetype = Chartvaluetype. String; Set the value type on the x-axis CT. series[0]. Label ="#VAL"; Set the value of x y to display CT. series[0]. ToolTip ="#VALX年 \r#val"; The mouse moves to the corresponding point to display the numerical CT. series[0]. ChartArea ="CA1"; Set Chart Background Box ct. series[0]. ChartType = Seriescharttype. Line; Graph type (polyline) CT. series[0]. Points. DATABINDXY (TXDATA2, TYDATA2); Add Data//broken segment Configuration ct. series[0]. color = Color. Red; Line Color CT. series[0]. BorderWidth =3; Line Thickness CT. series[0]. Markerbordercolor =color. Red; Mark Point Border Color ct. series[0]. Markerborderwidth=3; Mark Point Border Size CT. series[0]. Markercolor =color. Red; Mark Point Center Color CT. series[0]. Markersize =5; Mark Point Size CT. series[0]. Markerstyle=markerstyle. Circle; Marker Point Type CT. Series. ADD (New Series ()); Add a chart sequence CT. series[1]. Label ="#VAL"; Set the value of x y to display CT. series[1]. ToolTip ="#VALX年 \r#val"; The mouse moves to the corresponding point to display the numerical CT. series[1]. ChartType = Seriescharttype. Line; Graph type (polyline) CT. series[1]. Points. DATABINDXY (TXDATA3, TYDATA3); Add Data//broken segment Configuration ct. series[1]. color = Color. Black; Line Color CT. series[1]. BorderWidth =3; Line Thickness CT. series[1]. Markerbordercolor = Color. Black; Mark Point Border Color ct. series[1]. Markerborderwidth =3; Mark Point Border Size CT. series[1]. Markercolor = Color. Black; Mark Point Center Color CT. series[1]. Markersize =5; Mark Point Size CT. series[1]. MarkerStyle = MarkerStyle. Circle//Mark point type//additional//Pie chart Description settings, this is used to set the pie chart where the information for each block is displayed Ct0][ "pielabelstyle"] =  " Outside ";//move text to the outside Ct0][ "pielinecolor"] =  "Black ";//draw black lines. Bar chart Other Settings Ct0][ "drawingstyle"] =  " Emboss "0][ "pointwidth"] =  "0.5" Span class= "hljs-comment" >; Set column size                

Example diagram
To run the example, I'm using a line chart

Where the data source is bound, there are two ways to get a line chart.

1, read the database, get the data set, bind the corresponding column to get the line graph: DataSet ds = Read the database; DataView dv=new DataView (ds. Tables[0]); This.chart1.series[0]. Charttype=seriescharttype.line; This.chart1.series[0]. POINTS.DATABINDXY (DV, "Time column Column name", DV, "Temperature column Column name"); 2, read the database, get the data list, the binding list to get the line graph:list<datetime> x = Read the database to get a time list; List<double> y = Read the database to get a list of temperatures; This.chart1.series[0]. Charttype=seriescharttype.line; This.chart1.series[0]. POINTS.DATABINDXY (x, y);

Use the WinForm Chart control to make pie, columnar, line charts

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.