Drawing a multi-graph table with MSChart control (reprint)

Source: Internet
Author: User

In the. Net4.0 framework, Microsoft has integrated the MSChart control, has been used under the Web, the original WinForm under the MSChart control more simple and more convenient, today we use MSChart to draw a multi-graph, words do not say, directly on:

found that the MsChart display effect is good.

The code is as follows for your reference:

Public partial class Frmmain:form {public Frmmain () {InitializeComponent ();            InitializeChart (); This.            Load + = new EventHandler (frmmain_load);        This.myChart.GetToolTipText + = new eventhandler<tooltipeventargs> (mychart_gettooltiptext);            } void Frmmain_load (object sender, EventArgs e) {float[][] data = new float[3][];            First Data data[0] = new FLOAT[10] {1.3f, 2.5f, 2.1f, 3.3f, 2.8f, 3.9f, 4.3f, 3.6f, 4.2f, 3.6f};            Second data data[1] = new Float[12] { -2f, -1.3f, 0.1f, 0.5f, -1.5f, 0.7f, 1f, 1.4f, 1.9f, 2f, 2.6f, 3.1f};            Third data data[2] = new FLOAT[10] {7.8f, 9.2f, 6.5f, 8.3f, 9.0f, 5.9f, 6.3f, 7.2f, 8.8f, 9.8f}; for (int i = 0; i < data. Length;                i++) {//Horizontal axis time datetime dt = DateTime.Now.Date; Series Series = this.                Setseriesstyle (i); for (int j = 0; J < Data[i]. Length; J + +) {series.                    POINTS.ADDXY (DT, data[i][j]); DT = dt.                AddDays (1);            } this.myChart.Series.Add (Series); }} private void Mychart_gettooltiptext (object sender, Tooltipeventargs e) {if (e.hittest                Result.chartelementtype = = chartelementtype.datapoint) {int i = 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 char control style///</summary> public void Initializechar            T () {#region Set the chart's properties//Chart background color Mychart.backcolor = COLOR.FROMARGB (211, 223, 240);            Chart background color gradient mode Mychart.backgradientstyle = Gradientstyle.topbottom;       The border color of the chart,     Mychart.borderlinecolor = Color.FromArgb (26, 59, 105);            Chart border line Style Mychart.borderlinedashstyle = Chartdashstyle.solid;            Chart border line width mychart.borderlinewidth = 2;            Chart border of skin MyChart.BorderSkin.SkinStyle = Borderskinstyle.emboss;            #endregion #region Set the title title of the chart title = new title (); Title content is title.            Text = "Multi-graph demonstration"; Title of the font title.            Font = new System.Drawing.Font ("Microsoft Sans Serif", fontstyle.bold); Title Font Color title.            ForeColor = Color.FromArgb (26, 59, 105); Title Shadow color title.            Shadowcolor = Color.FromArgb (32, 0, 0, 0); Title Shadow offset title.            Shadowoffset = 3;            MYCHART.TITLES.ADD (title);            #endregion #region Set the chart area properties//Chart Area name ChartArea ChartArea = new ChartArea ("Default"); Background color Chartarea.backcolor = COLOR.FROMARGB (64, 165, 191, 228);            Background gradient mode chartarea.backgradientstyle = Gradientstyle.topbottom;            Secondary background color for gradients and shadows chartarea.backsecondarycolor = Color.White;            Border color Chartarea.bordercolor = Color.FromArgb (64, 64, 64, 64);            Shadow color chartarea.shadowcolor = color.transparent;            Sets the color and width of the x-axis and y-axis bars ChartArea.AxisX.LineColor = Color.FromArgb (64, 64, 64, 64);            ChartArea.AxisX.LineWidth = 1;            ChartArea.AxisY.LineColor = Color.FromArgb (64, 64, 64, 64);            ChartArea.AxisY.LineWidth = 1;            Set the x-axis and y-axis Title chartArea.AxisX.Title = "Horizontal axis title";            ChartArea.AxisY.Title = "ordinate title";            Sets the color and width of the horizontal vertical line of the chart area grid ChartArea.AxisX.MajorGrid.LineColor = Color.FromArgb (64, 64, 64, 64);            ChartArea.AxisX.MajorGrid.LineWidth = 1;            ChartArea.AxisY.MajorGrid.LineColor = Color.FromArgb (64, 64, 64, 64); ChartArea.AxisY.MajorGrid.LineWidth = 1;            MYCHART.CHARTAREAS.ADD (ChartArea);            #endregion #region The location of the legend and the legend Legend Legend = new Legend (); Legend.            Alignment = Stringalignment.center; Legend.            Docking = Docking.bottom;            THIS.MYCHART.LEGENDS.ADD (legend); #endregion}//Set series style private series Setseriesstyle (int i) {Series series = NE W Series (String.            Format ("{0} data", I + 1)); The type series of the series.            ChartType = Seriescharttype.line; The series's border color series.            BorderColor = Color.FromArgb (180, 26, 59, 105); Line width series.            BorderWidth = 3; Line Shadow color series.            Shadowcolor = Color.Black; Shadow width series.            Shadowoffset = 2; Whether the data Description series is displayed.            Isvisibleinlegend = true; Whether there is a data display series on the data points on the line.            Isvalueshownaslabel = false; The data point marker type series on the line. MarkerStyle = MarkerStyle.circle; The size of the line data point series.            Markersize = 8; Line Color switch (i) {case 0:series.                    Color = Color.FromArgb (220, 65, 140, 240);                Break Case 1:series.                    Color = Color.FromArgb (220, 224, 64, 10);                Break Case 2:series.                    Color = Color.FromArgb (220, 120, 150, 20);            Break        } return series; }    }

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.

Reprint: http://www.cnblogs.com/lxblog/

Drawing a multi-graph table with MSChart control (reprint)

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.