C # Chart Control drawing curves

Source: Internet
Author: User

In. NET before, often with GDI to draw, although the effect is good, since the beginning of. NET 4.0, a chart control specifically for charting has appeared, with it, you can easily draw the graphs you need, histograms and so on.

Using system;using system.collections.generic;using system.linq;using system.text;using System.Windows.Forms;using System.windows.forms.datavisualization.charting;using System.Drawing; namespace drawgraph{//<summary>///Draw curve class///</summary> public static class Drawclass {#region draw Curve function///<summary>///Draw curve function////</summary>//<param name= "Listx" >x value collection </param&         Gt <param name= "listy" >y value collection </param>///<param Name= "chart" >chart controls </param> Publi             c static void DrawSpline (List<int> listx, list<double> listy, chart chart) {Try {//x, Y-value member chart. Series[0].                 POINTS.DATABINDXY (Listx, listy); Chart. Series[0].                 Points.databindy (listy); Dot Color Chart. Series[0].                 Markercolor = Color.green; The chart type is set to the spline curve chart. Series[0]. ChartType = SerieScharttype.spline; Sets the size of the point chart. Series[0].                 Markersize = 5; Sets the color of the curve chart. Series[0].                 Color = Color.orange; Set the curve width chart. Series[0].                 BorderWidth = 2; Chart. Series[0].                 CustomProperties = "pointwidth=4"; Sets whether the coordinate callout chart is displayed. Series[0].                 Isvalueshownaslabel = false; Sets the cursor chart. Chartareas[0].                 Cursorx.isuserenabled = true; Chart. Chartareas[0].                 Cursorx.autoscroll = true; Chart. Chartareas[0].                 Cursorx.isuserselectionenabled = true; Sets whether the X-axis can scale the chart. Chartareas[0].                 AxisX.ScaleView.Zoomable = true; Place the scroll bar outside the chart. Chartareas[0].                 AxisX.ScrollBar.IsPositionedInside = false; Sets the size of the scroll bar chart. Chartareas[0].                 AxisX.ScrollBar.Size = 15; To set the style of the button for the scrollbar, the following code shows all the buttons on the scroll bar. ChaRt. Chartareas[0].                 AxisX.ScrollBar.ButtonStyle = Scrollbarbuttonstyles.all; Chart. Chartareas[0].                 AxisX.ScrollBar.ButtonColor = Color.skyblue; Sets the minimum amount of automatic zoom and zoom chart. Chartareas[0]. AxisX.ScaleView.SmallScrollSize = Double.                 NaN; Chart. Chartareas[0].                 AxisX.ScaleView.SmallScrollMinSize = 1; Set the tick interval chart. Chartareas[0].                 Axisx.interval = 10; Cancels the chart on the x-axis grid. Chartareas[0].                 AxisX.MajorGrid.Enabled = false; X-axis, y-axis title chart. Chartareas[0].                 Axisx.title = "ring number"; Chart. Chartareas[0].                 Axisy.title = "diameter";                 Set the y-axis range to re-modify double max = listy[0] According to the actual situation;                 Double min = listy[0];                         foreach (Var yvalue in listy) {if (Max < Yvalue) {                     max = Yvalue; } if (Min > YValue) {min = Yvalue; }} chart. Chartareas[0].                 Axisy.maximum = max; Chart. Chartareas[0].                 axisy.minimum = min; Chart. Chartareas[0].                 Axisy.interval = (max-min)/10; Binds the data source chart.             DataBind (); } catch (Exception exc) {MessageBox.Show (exc.             ToString ()); }} #endregion #region mouse click, display the cursor through the ring number, and zoom to the response location///<summary>//mouse click, through the ring number display cursor, and zoom to the response position function///</summary>//<param name= "Ringnum" > Ring </param>//<param             Name= "Chart" >chart control </param> public static void Showcurbyclick (int ringnum, chart chart) { Sets the cursor position of the chart. Chartareas[0].             Cursorx.position = Ringnum; Set the view Zoom chart. Chartareas[0]. AxisX.ScaleView.Zoom (RingNum-1, Ringnum + 2); Change the Curve line width chart. Series[0].             BorderWidth = 3; Change the x-axis scale interval chart. Chartareas[0].         Axisx.interval = 1; } #endregion}}

Reference articles
1. Drawing graphs using the. NET chart control

C # Chart Control drawing curves

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.