C # 's Chart article

Source: Internet
Author: User
叕 叕 叕 to Friday, time always go so fast, unavoidably sad (-) ... (Sad a wool, again sad 16 is gone) December will be over, hurriedly to a full life. Recently in the project, made a chart program, using the chart, today to do a collation summary. 1. The first chart control 1 First to familiarize yourself with the chart, in front of a chart may be used to chart.js, in C # can be used with the control of the chart, feel very convenient. 2 Create a project, Windows Forms application. Locate the "Chart" control in the Toolbox's data and drag it to the form

3 Right Key Chart "Properties", in vs Right Property "layout" to find the "Dock" property set to fill, adjust the size yourself

4 The operation here is to display chart when the form is loaded, so there is a form load event.

5 Double-click directly into the code, when written in the code Series will appear red wavy lines, prompted the lack of related namespaces and so on, click "Series" can see the need, add on the OK

6) Code

Using System;
Using System.Collections.Generic;
Using System.ComponentModel;
Using System.Data;
Using System.Drawing;
Using System.Linq;
Using System.Text;
Using System.Windows.Forms;

Using System.Windows.Forms.DataVisualization.Charting; namespace MyChart {public partial class Form1:form {public Form1 () {initializecom
        Ponent (); The private void Form1_Load (object sender, EventArgs e) {//Clears the default series Chart1.
            Series.clear ();  
            New a series called "strength" Series strength = new Series ("Power");
            Sets the type of the chart, here for the columnar graph strength.charttype = seriescharttype.column;
            Assign values to the points on the series, respectively corresponding to the horizontal and ordinate values Strength.Points.AddXY ("A", "90");
            Strength.Points.AddXY ("B", "88");
            Strength.Points.AddXY ("C", "60");
            Strength.Points.AddXY ("D", "93");
            Strength.Points.AddXY ("E", "79"); Strength.Points.AddXY ("F", "85")); Add the series to the chart Chart1.       

        Series.add (strength); }
    }
}
7) Effect Chart

2. Two series 1) Right-click the project name and add a Windows Form. And then the steps are the same as in the front, and there's not much to say about 2. Simple Rough Code

Using System;
Using System.Collections.Generic;
Using System.ComponentModel;
Using System.Data;
Using System.Drawing;
Using System.Linq;
Using System.Text;
Using System.Windows.Forms;
Using System.Windows.Forms.DataVisualization.Charting;

Namespace MyChart
{
public partial class Form2:form
{
Public Form2 ()
{
InitializeComponent ();
}

    private void Form2_load (object sender, EventArgs e) {Chart1.
        Series.clear ();
        Series strength = new Series ("Power");

        Series speed= New Series ("Speed");
        Strength.charttype = Seriescharttype.column;
        Strength.isvalueshownaslabel = true;

        Strength.color = System.Drawing.Color.Cyan;
        Speed.charttype = Seriescharttype.spline;

        Speed.isvalueshownaslabel = true; Chart1. Chartareas[0].
        AxisX.MajorGrid.Interval = 0.5; Chart1. Chartareas[0].
        AxisX.MajorGrid.Enabled =true; Chart1. Chartareas[0].
        Area3dstyle.enable3d = true; Chart1. Chartareas[0].
        Axisx.ismarginvisible = true; Chart1. Chartareas[0].
        Axisx.title = "Hero"; Chart1. Chartareas[0].

        Axisx.titleforecolor = System.Drawing.Color.Crimson; Chart1. Chartareas[0].
        Axisy.title = "attribute"; Chart1. Chartareas[0].
        Axisy.titleforecolor = System.Drawing.Color.Crimson; Chart1. Chartareas[0]. Axisy.textorientation = Textorientation.horizoNtal;
        Strength.legendtext = "Strength";
        Strength.Points.AddXY ("A", "90");
        Strength.Points.AddXY ("B", "88");
        Strength.Points.AddXY ("C", "60");
        Strength.Points.AddXY ("D", "93");
        Strength.Points.AddXY ("E", "79");

        Strength.Points.AddXY ("F", "85");
        Speed.Points.AddXY ("A", "120");
        Speed.Points.AddXY ("B", "133");
        Speed.Points.AddXY ("C", "100");
        Speed.Points.AddXY ("D", "98");
        Speed.Points.AddXY ("E", "126");

        Speed.Points.AddXY ("F", "89"); Add the series to the chart Chart1. 
        Series.add (Speed); Chart1.

    Series.add (strength);
 }
}

} 3) Effect

4 familiar with common properties and Methods (1) Series Objects

Series strength = new Series ("Power");
Series speed= New Series ("Speed"); Set Series Type

Strength.charttype = Seriescharttype.column;
Speed.charttype = Seriescharttype.spline; whether to display the value as a label (default false)

Speed.isvalueshownaslabel = true; Set Series color

Strength.color = System.Drawing.Color.Cyan; assign a value to a point on a series

            Strength.Points.AddXY ("A", "the");
            Strength.Points.AddXY ("B", "the");
            Strength.Points.AddXY ("C", "60");
(2) ChartArea (which is the area we see) Show in the form of a

Chart1. Chartareas[0]. Area3dstyle.enable3d = true; Set axis Title

   Chart1. Chartareas[0]. Axisy.title = "attribute";
            Chart1. Chartareas[0]. Axisy.titleforecolor = System.Drawing.Color.Crimson;
            Chart1. Chartareas[0]. Axisy.textorientation = Textorientation.horizontal;
Set the grid interval (set to 0.5 here to see a little more intuitive)
Chart1. Chartareas[0]. AxisX.MajorGrid.Interval = 0.5;
3. Stock fluctuation 1) Main code
Using Daisy.Common.McsClient;
Using System;
Using System.Collections.Generic;
Using System.ComponentModel;
Using System.Data;
Using System.Drawing;
Using System.Linq;
Using System.Text;
Using System.Windows.Forms;

Using System.Windows.Forms.DataVisualization.Charting; namespace Bizwhonhandquery {public partial class MainForm:Mes.ControlsEx.ExtendForm.BaseForm {public S Tring QuerySql01 = string.
        Empty;
        Public MainForm () {InitializeComponent ();
        } private void Navigatorex1_onquery (object sender, Mes.Core.ApplicationObject.SystemNavigatorClickedEventArgs e)
                {try {queryform QF = new Queryform (); Qf.
                StartPosition = Formstartposition.centerscreen; Qf.
                ShowDialog (); if (QF. DialogResult = = System.Windows.Forms.DialogResult.OK) {QuerySql01 = QF.
                            QUERYSQL01; This.chart1.Series. Clear ()///Set the x/y style Chart1 first series//. Chartareas[0].
                            Axisy.title = Mes.Core.Utility.StrUtil.Translate ("Quantity"); Chart1. Chartareas[0].
                            Axisx.title = Mes.Core.Utility.StrUtil.Translate ("date"); Chart1. Chartareas[0].
                            AxisX.LabelStyle.Angle = 0; Chart1. Chartareas[0].
                            Axisx.intervalautomode = Intervalautomode.variablecount; Chart1. Chartareas[0].
                            Axisy.intervalautomode = Intervalautomode.variablecount; Chart1. Chartareas[0].
                            axisx.enabled = Axisenabled.false; Chart1. Chartareas[0].
                            axisy.enabled = Axisenabled.false; Chart1. Titles[0].

                            Text = "";
                            Sets the char style THIS.CHART1.SERIES.ADD (Mes.Core.Utility.StrUtil.Translate ("Quantity")); Chart1. Series[mes.core.utility.strutil.translAte ("Quantity")]. Markercolor = color.black;//Set flag Chart1. Series[mes.core.utility.strutil.translate ("Quantity")].
                            Markersize = 1; Chart1. Series[mes.core.utility.strutil.translate ("Quantity")].
                            MarkerStyle = Markerstyle.square; Chart1. Series[mes.core.utility.strutil.translate ("Quantity")]. Isvalueshownaslabel = false;//Whether value Chart1 is displayed. Series[mes.core.utility.strutil.translate ("Quantity")]. ChartType = seriescharttype.spline;//Set display style Chart1. Series[mes.core.utility.strutil.translate ("Quantity")].
                            BorderWidth = 1; Chart1. Series[mes.core.utility.strutil.translate ("Quantity")].
                            Color = Color.Blue; Chart1. Series[mes.core.utility.strutil.translate ("Quantity")].
                            ToolTip = Mes.Core.Utility.StrUtil.Translate ("Quantity of raw materials"); Chart1. Series[mes.core.utility.strutil.translate ("Quantity")].

                         Yvaluetype = chartvaluetype.double;   Mcsdatareader reader = (mcsdatareader) Mes.Core.Service.DatabaseAccessService.execute (QF.
                            QUERYSQL01, Mes.Core.Service.ReturnType.RESULTSET); if (Reader.rownumber > 0) {while reader. Read ()) {Chart1. Series[mes.core.utility.strutil.translate ("Quantity")].
                                POINTS.ADDXY (reader.getstring (1), reader.getstring (0)); }} Chart1. Chartareas[0].
                            Axisy.minimum = 0; Chart1. Chartareas[0]. AXES[1].
                            Labelstyle.format = "N0"; The catch (Exception ex) {MessageBox.Show ( Ex.
                message);
            Return }   
        }
    }
2) Effect Chart

4. Equipment Usage Analysis Check the frequency of the device at a certain time range (available by day or week or month) and click a record to see the corresponding curve. The report's devices include devices that have records of the underlying data being maintained, and devices that have records that do not maintain the underlying data ( 1) Functional Code structure

2) MainForm

Using Daisy.Common.McsClient;
Using System;
Using System.Collections.Generic;
Using System.ComponentModel;
Using System.Data;
Using System.Drawing;
Using System.Linq;
Using System.Text;

Using System.Windows.Forms; namespace Bizdeviceuseanalysis {public partial class MainForm:Mes.ControlsEx.ExtendForm.BaseForm {Quer
        Yform form = null;
        Public MainForm () {InitializeComponent ();
        } private void Navigatorex1_onquery (object sender, Mes.Core.ApplicationObject.SystemNavigatorClickedEventArgs e)
             {form = new queryform (); Form.
             ShowDialog (); if (form.

            DialogResult = = System.Windows.Forms.DialogResult.OK) {GetData ();           } void GetData () {try {addcolumns ();
            Gets the column name Adddataingridview ();
              catch (Exception ex) {  MessageBox.Show (ex.
            message); } void Addcolumns () {try {list<string> Columnlis
                t = new list<string> (); Mcsdatareader reader = (mcsdatareader) Mes.Core.Service.DatabaseAccessService.execute (Form.colsql,
                Mes.Core.Service.ReturnType.RESULTSET); Mcsdatareader Reader01 = (mcsdatareader) Mes.Core.Service.DatabaseAccessService.execute (form.
                Querysql, Mes.Core.Service.ReturnType.RESULTSET); while (reader.

                    Read ()) {String calendar = reader.getstring (0); if (form. Kind = = 1) {calendar = DateTime.Parse (Calendar).

                    ToString ("Yyyy-mm-dd"); }//if (Form. Kind = = 2//{//calendar = DateTime.Parse (Calendar).

                    ToString ("Yyyy-iw"); }//if (Form. KIND = = 3//{//calendar = DateTime.Parse (Calendar).

                    ToString ("yyyy-mm");


                } columnlist.add (Calendar);

                } if (Columnlist.count = 0) return;
                int count = This.dataGridViewEx1.Columns.Count;
                for (int j = count-1 J > 2; j--) {this.dataGridViewEx1.Columns.RemoveAt (j); for (int i =

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.