Drawing a multi-curve chart with MSChart controls

Source: Internet
Author: User
Tags border color

In the. Net4.0 framework, Microsoft has integrated the MSChart control, has been used under the Web, the original WinForm under the MSChart control simpler and more convenient, today we use MSChart to draw a multi-graph, found MSChart The display effect is good, words not much to say, directly on:

The code is as follows for your reference:

 Public Partial classFrmmain:form { PublicFrmmain () {InitializeComponent ();            InitializeChart ();  This. Load + =NewEventHandler (frmmain_load);  This. Mychart.gettooltiptext + =NewEventhandler<tooltipeventargs>(Mychart_gettooltiptext); }        voidFrmmain_load (Objectsender, EventArgs e) {            float[] data =New float[3][]; //The first piece of datadata[0] =New float[Ten] {1.3f,2.5f,2.1f,3.3f,2.8f,3.9f,4.3f,3.6f,4.2f,3.6f }; //The second piece of datadata[1] =New float[ A] { -2f,-1.3f,0.1f,0.5f, -1.5f,0.7f, 1f,1.4f,1.9f, 2f,2.6f,3.1f }; //The third piece of datadata[2] =New float[Ten] {7.8f,9.2f,6.5f,8.3f,9.0f,5.9f,6.3f,7.2f,8.8f,9.8f };  for(inti =0; I < data. Length; i++)            {                //Horizontal TimeDateTime dt =DateTime.Now.Date; Series Series= This.                Setseriesstyle (i);  for(intj =0; J < Data[i]. Length; J + +) {series.                    POINTS.ADDXY (DT, data[i][j]); DT= dt. AddDays (1); }                 This. MYCHART.SERIES.ADD (Series); }        }        Private voidMychart_gettooltiptext (Objectsender, Tooltipeventargs e) {            if(E.hittestresult.chartelementtype = =chartelementtype.datapoint) {inti =E.hittestresult.pointindex; Datapoint DP=E.hittestresult.series.points[i]; E.text=string. Format ("time: {0}; Value: {1:F1}", Datetime.fromoadate (DP. XValue), DP. yvalues[0]); }        }        /// <summary>        ///initialize a char control style/// </summary>         Public voidInitializeChart () {#regionSet the properties of a chart//background color of the chartMychart.backcolor = Color.FromArgb (211,223, -); //how the chart background color fadesMychart.backgradientstyle =Gradientstyle.topbottom; //the border color of the chart,Mychart.borderlinecolor = Color.FromArgb ( -, -, the); //border line style for chartsMychart.borderlinedashstyle =Chartdashstyle.solid; //width of chart border linesMychart.borderlinewidth =2; //the skin of the chart borderMyChart.BorderSkin.SkinStyle =Borderskinstyle.emboss; #endregion            #regionSet the title of the chartTitle Title=NewTitle (); //Title ContentTitle. Text ="Multi-Graph demo"; //Font for headingsTitle. Font =NewSystem.Drawing.Font ("Microsoft Sans Serif", A, FontStyle.Bold); //Title Font ColorTitle. ForeColor = Color.FromArgb ( -, -, the); //title Shadow colorTitle. Shadowcolor = Color.FromArgb ( +,0,0,0); //Title Shadow offsetTitle. Shadowoffset =3;            MYCHART.TITLES.ADD (title); #endregion            #regionSet chart Area Properties//the name of the chart areaChartArea ChartArea =NewChartArea ("Default"); //Background ColorChartarea.backcolor = Color.FromArgb ( -,165,191,228); //Background Gradient modeChartarea.backgradientstyle =Gradientstyle.topbottom; //secondary background color for gradients and shadowsChartarea.backsecondarycolor =Color.White; //Border ColorChartarea.bordercolor = Color.FromArgb ( -, -, -, -); //Shadow colorChartarea.shadowcolor =color.transparent; //set the color and width of the x-axis and y-axis barsChartArea.AxisX.LineColor = Color.FromArgb ( -, -, -, -); ChartArea.AxisX.LineWidth=1; ChartArea.AxisY.LineColor= Color.FromArgb ( -, -, -, -); ChartArea.AxisY.LineWidth=1; //set the title of the x-axis and y-axisChartArea.AxisX.Title ="Horizontal axis Title"; ChartArea.AxisY.Title="Ordinate title"; //set the color and width of the chart area grid horizontal linesChartArea.AxisX.MajorGrid.LineColor = Color.FromArgb ( -, -, -, -); ChartArea.AxisX.MajorGrid.LineWidth=1; ChartArea.AxisY.MajorGrid.LineColor= Color.FromArgb ( -, -, -, -); ChartArea.AxisY.MajorGrid.LineWidth=1;            MYCHART.CHARTAREAS.ADD (ChartArea); #endregion            #regionLocation of legend and legendLegend Legend=NewLegend (); Legend. Alignment=Stringalignment.center; Legend. Docking=Docking.bottom;  This. MYCHART.LEGENDS.ADD (legend); #endregion        }        //set the series style        PrivateSeries Setseriesstyle (inti) {Series Series=NewSeries (string. Format ("section {0} data"+ N +1)); //Type of seriesSeries. ChartType =Seriescharttype.line; //the border color of seriesSeries. BorderColor = Color.FromArgb ( the, -, -, the); //line widthSeries. BorderWidth =3; //Line Shadow colorSeries. Shadowcolor =Color.Black; //Shadow widthSeries. Shadowoffset =2; //whether to display data descriptionSeries. Isvisibleinlegend =true; //whether there is data on the data points on the lineSeries. Isvalueshownaslabel =false; //data point marker type on lineSeries. MarkerStyle =markerstyle.circle; //the size of the line data pointSeries. Markersize =8; //Line Color            Switch(i) { Case 0: series. Color= Color.FromArgb ( -, $, $, -);  Break;  Case 1: series. Color= Color.FromArgb ( -,224, -,Ten);  Break;  Case 2: series. Color= Color.FromArgb ( -, -, Max, -);  Break; }            returnseries; }    }

Also attached is the Microsoft Demo: http://archive.msdn.microsoft.com/mschart/Release/ProjectReleases.aspx?ReleaseId=4418

Demo is divided into Web version and WinForm version, style and chart content is very full, I hope to be helpful to everyone.

Source: http://www.cnblogs.com/lxblog/archive/2012/05/21/2511823.html

Drawing a multi-curve chart with MSChart controls

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.