当前位置:   article > 正文

【C#上位机】| (chart)控件 | -System.Windows.Forms.DataVisualization.dll_system.windows.forms.datavisualization dll下载

system.windows.forms.datavisualization dll下载

一、 介绍:图表控件Microsoft Chart Controls for Microsoft .NET Framework 3.5,通过它,可让您的项目及报表,轻松套用各种功能强大的 2D、3D、实时变化的动态图表;且透过 AJAX,可让图表及里面的数据,每秒钟都持续更新;使用者透过浏览器,可和图表做各种互动设定

2. 应用

要想利用这个功能强大的控件,首先必须引用以下DLL和相关文件: 在WinForm应用程序中要想使用该图表控件,需引用如下DLL:

>System.Windows.Forms.DataVisualization.Design.dll
>System.Windows.Forms.DataVisualization.dll
>System.Windows.Forms.DataVisualization.xml
  • 1
  • 2
  • 3

二、采用WinForm程序使用该图表控件

  1. 创建一个WinForm工程: DemoCollection

  2. 添加一个Form窗体: FrmChartDemo

  3. 添加所需的DLL引用

  4. 在该窗体的Load事件函数中动态创建好Chart对象实例

  5. 添加一个Timer控件,在Timer控件的Tick事件函数中向Chart中添加坐标值(X值和Y值),然后在窗体中绘制出来.

  6. FrmChartDemo的后台代码如下:

FrmChartDemo.cs:

using System.Windows.Forms.DataVisualization.Charting;
namespace DemoCollection

{
    public partial class FrmChartDemo : Form
    {
        #region the variable definiton
        private Chart chart1;
        private Random random = new Random();
        private int maxYValue = 20;
        private int minYValue = 0;
        #endregion
        #region Ctor
        public FrmChartDemo()
       {
            InitializeComponent()this.Load += new EventHandler(FrmChartDemo_Load);
            this.timer1.Tick += new EventHandler(timer1_Tick); 
     #endregion

        #region the event handler
        void FrmChartDemo_Load(object sender, EventArgs e)
        {
            #region from BBVS porject
            // Create a Chart
            chart1 = new Chart();
            // Create Chart Area
            ChartArea chartArea1 = new ChartArea();
            // Add Chart Area to the Chart
            chart1.ChartAreas.Add(chartArea1);
           #region Set the Chart
            // Set the chart style
            chart1.BackGradientStyle = System.Windows.Forms.DataVisualization.Charting.GradientStyle.TopBottom;

            chart1.BackSecondaryColor = System.Drawing.Color.White;

            chart1.BorderlineColor = System.Drawing.Color.FromArgb(((int)(((byte)(26)))), ((int)(((byte)(59)))), ((int)(((byte)(105)))));

            chart1.BorderlineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;

            chart1.BorderlineWidth = 2;

            chart1.BorderSkin.SkinStyle = System.Windows.Forms.DataVisualization.Charting.BorderSkinStyle.Emboss;

            chart1.BackColor = Color.SteelBlue;

            chart1.Dock = DockStyle.Fill;



            chartArea1.Area3DStyle.Inclination = 15;

            chartArea1.Area3DStyle.IsClustered = true;

            chartArea1.Area3DStyle.IsRightAngleAxes = false;

            chartArea1.Area3DStyle.Perspective = 10;

            chartArea1.Area3DStyle.Rotation = 10;

            chartArea1.Area3DStyle.WallWidth = 0;

            // 设置是否启用 3D 效果

            //chartArea1.Area3DStyle.Enable3D = true

            chartArea1.AxisX.LabelStyle.Font = new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);
            chartArea1.AxisX.LabelStyle.Format = "hh:mm:ss";
            chartArea1.AxisX.LabelStyle.Interval = 5D; // 10D;
           chartArea1.AxisX.LabelStyle.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Seconds;

            chartArea1.AxisX.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
            chartArea1.AxisX.MajorGrid.Interval = 5D; // 10D;
            chartArea1.AxisX.MajorGrid.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Seconds;
            chartArea1.AxisX.MajorGrid.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
            chartArea1.AxisX.MajorTickMark.Interval = 5D; // 10D;
            chartArea1.AxisX.MajorTickMark.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Seconds;

            chartArea1.AxisY.IsLabelAutoFit = false;
            chartArea1.AxisY.IsStartedFromZero = false;
            chartArea1.AxisY.LabelStyle.Font = new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);
            chartArea1.AxisY.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
            chartArea1.AxisY.MajorGrid.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));

            #region 设置 Y 轴的 最大值和 最小值

            chartArea1.AxisY.Maximum = this.maxYValue + 6; 
            chartArea1.AxisY.Minimum = this.minYValue - 6;

            #endregion

            chartArea1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(165)))), ((int)(((byte)(191)))), ((int)(((byte)(228)))));
            chartArea1.BackGradientStyle = System.Windows.Forms.DataVisualization.Charting.GradientStyle.TopBottom;
            chartArea1.BackSecondaryColor = System.Drawing.Color.White;
            chartArea1.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
            chartArea1.BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;

            chartArea1.InnerPlotPosition.Auto = false;
            chartArea1.InnerPlotPosition.Height = 85F;
            chartArea1.InnerPlotPosition.Width = 86F;
            chartArea1.InnerPlotPosition.X = 8.3969F;
            chartArea1.InnerPlotPosition.Y = 3.63068F;

            chartArea1.Name = "Default";
            chartArea1.Position.Auto = false;
            chartArea1.Position.Height = 86.76062F;
            chartArea1.Position.Width = 88F;
            chartArea1.Position.X = 5.089137F;
            chartArea1.Position.Y = 5.895753F;
            chartArea1.ShadowColor = System.Drawing.Color.Transparent;

            #endregion

            #region Create a Legend

            Legend legend1 = new Legend();
            legend1.Alignment = System.Drawing.StringAlignment.Far;
            legend1.BackColor = System.Drawing.Color.Transparent;
            legend1.DockedToChartArea = "Default";
            legend1.Docking = System.Windows.Forms.DataVisualization.Charting.Docking.Top;
            legend1.Font = new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);
            legend1.IsTextAutoFit = false;
            legend1.LegendStyle = System.Windows.Forms.DataVisualization.Charting.LegendStyle.Row;
            legend1.Name = "Default";
            chart1.Legends.Add(legend1);

            #endregion

            #region Create a Series

            Series series1 = new Series();
            series1.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(180)))), ((int)(((byte)(26)))), ((int)(((byte)(59)))), ((int)(((byte)(105)))));
            series1.ChartArea = "Default";
            series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.FastLine;//Line;
            series1.Color = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(64)))), ((int)(((byte)(10)))));

            series1.Legend = "Default";
            series1.Name = "Series1";
            series1.ShadowOffset = 1;
            series1.YValuesPerPoint = 2;
            chart1.Series.Add(series1);

            // 设置是否在 Chart 中显示 坐标点值
            series1.IsValueShownAsLabel = true;

            #endregion

            // Set chart control location
            chart1.Location = new System.Drawing.Point(0, 0);

            // Add chart control to the form
            this.Controls.AddRange(new System.Windows.Forms.Control[] { this.chart1 });

            #endregion
        }

        void timer1_Tick(object sender, EventArgs e)
        {
            double tempValue = 0.0;

            // 随机产生 温度值
            tempValue = random.Next(this.minYValue, this.maxYValue);

            DateTime timeStamp = DateTime.Now;
            double xValue = DateTime.Now.ToOADate();

            // 向 Chart中 添加 X轴 和 Y轴的 值
            chart1.Series["Series1"].Points.AddXY(xValue, tempValue);

            // remove all points from the source series older than 20 seconds.
            double removeBefore = timeStamp.AddSeconds((double)(20) * (-1)).ToOADate();

            //remove oldest values to maintain a constant number of data points
            if (chart1.Series[0].Points.Count > 0)
            {
                while (chart1.Series[0].Points[0].XValue < removeBefore)
                {
                    chart1.Series[0].Points.RemoveAt(0);
                }

                chart1.ChartAreas[0].AxisX.Minimum = chart1.Series[0].Points[0].XValue;
                chart1.ChartAreas[0].AxisX.Maximum = DateTime.FromOADate(chart1.Series[0].Points[0].XValue).AddSeconds(20).ToOADate();
            }
            else
            {
                //chart1.ChartAreas[0].AxisX.Minimum = (double)minTempThreshold;
                //chart1.ChartAreas[0].AxisX.Maximum = (double)maxTempThreshold;
            }
            chart1.Invalidate();
        }
        #endregion
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194

参考:https://blog.csdn.net/a5pansq/article/details/89430307

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/398534
推荐阅读
相关标签
  

闽ICP备14008679号