加载表单时,c#chart轴不显示

时间:2016-12-13 17:35:00

标签: c# user-interface graph charts

由于某种原因,轴和网格未显示在c#图表上。正如你从两张图片中看到的那样,图表的背景正在显示,但没有别的。任何人都可以帮我弄清楚为什么没有显示图表中的网格和信息?

视觉工作室设计师的表格:

enter image description here

运行时的表单:

enter image description here

namespace Harman.Generic.Framework.WaveformMaker
{
    partial class WaveformMaker
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
            System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend();
            System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series();
            this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
            this.mnuStrip = new System.Windows.Forms.MenuStrip();
            this.mnuFile = new System.Windows.Forms.ToolStripMenuItem();
            this.mnuFileSaveWaveform = new System.Windows.Forms.ToolStripMenuItem();
            this.mnuFileExit = new System.Windows.Forms.ToolStripMenuItem();
            this.btnRun = new System.Windows.Forms.Button();
            this.lblPointVoltage = new System.Windows.Forms.Label();
            this.lblPointDuration = new System.Windows.Forms.Label();
            this.dgdPointList = new System.Windows.Forms.DataGridView();
            this.colPoint = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.colVoltage = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.colDuration = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.btnRemovePoint = new System.Windows.Forms.Button();
            this.btnAddPoint = new System.Windows.Forms.Button();
            this.chWaveform = new System.Windows.Forms.DataVisualization.Charting.Chart();
            this.mnuStrip.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.dgdPointList)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.chWaveform)).BeginInit();
            this.SuspendLayout();
            // 
            // contextMenuStrip1
            // 
            this.contextMenuStrip1.Name = "contextMenuStrip1";
            this.contextMenuStrip1.Size = new System.Drawing.Size(61, 4);
            // 
            // mnuStrip
            // 
            this.mnuStrip.BackColor = System.Drawing.SystemColors.Control;
            this.mnuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.mnuFile});
            this.mnuStrip.Location = new System.Drawing.Point(0, 0);
            this.mnuStrip.Name = "mnuStrip";
            this.mnuStrip.Size = new System.Drawing.Size(894, 24);
            this.mnuStrip.TabIndex = 2;
            this.mnuStrip.Text = "menuStrip1";
            // 
            // mnuFile
            // 
            this.mnuFile.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.mnuFileSaveWaveform,
            this.mnuFileExit});
            this.mnuFile.Name = "mnuFile";
            this.mnuFile.Size = new System.Drawing.Size(37, 20);
            this.mnuFile.Text = "File";
            // 
            // mnuFileSaveWaveform
            // 
            this.mnuFileSaveWaveform.Name = "mnuFileSaveWaveform";
            this.mnuFileSaveWaveform.Size = new System.Drawing.Size(156, 22);
            this.mnuFileSaveWaveform.Text = "Save Waveform";
            // 
            // mnuFileExit
            // 
            this.mnuFileExit.Name = "mnuFileExit";
            this.mnuFileExit.Size = new System.Drawing.Size(156, 22);
            this.mnuFileExit.Text = "Exit";
            // 
            // btnRun
            // 
            this.btnRun.Location = new System.Drawing.Point(621, 562);
            this.btnRun.Name = "btnRun";
            this.btnRun.Size = new System.Drawing.Size(83, 23);
            this.btnRun.TabIndex = 4;
            this.btnRun.Text = "Run";
            this.btnRun.UseVisualStyleBackColor = true;
            // 
            // lblPointVoltage
            // 
            this.lblPointVoltage.AutoSize = true;
            this.lblPointVoltage.Location = new System.Drawing.Point(10, 572);
            this.lblPointVoltage.Name = "lblPointVoltage";
            this.lblPointVoltage.Size = new System.Drawing.Size(49, 13);
            this.lblPointVoltage.TabIndex = 6;
            this.lblPointVoltage.Text = "Voltage: ";
            // 
            // lblPointDuration
            // 
            this.lblPointDuration.AutoSize = true;
            this.lblPointDuration.Location = new System.Drawing.Point(65, 572);
            this.lblPointDuration.Name = "lblPointDuration";
            this.lblPointDuration.Size = new System.Drawing.Size(58, 13);
            this.lblPointDuration.TabIndex = 7;
            this.lblPointDuration.Text = "Time (ms): ";
            // 
            // dgdPointList
            // 
            this.dgdPointList.AllowUserToAddRows = false;
            this.dgdPointList.AllowUserToResizeColumns = false;
            this.dgdPointList.AllowUserToResizeRows = false;
            this.dgdPointList.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dgdPointList.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
            this.colPoint,
            this.colVoltage,
            this.colDuration});
            this.dgdPointList.Location = new System.Drawing.Point(710, 28);
            this.dgdPointList.MultiSelect = false;
            this.dgdPointList.Name = "dgdPointList";
            this.dgdPointList.RowHeadersVisible = false;
            this.dgdPointList.ScrollBars = System.Windows.Forms.ScrollBars.None;
            this.dgdPointList.Size = new System.Drawing.Size(172, 528);
            this.dgdPointList.TabIndex = 8;
            // 
            // colPoint
            // 
            this.colPoint.HeaderText = "Point";
            this.colPoint.Name = "colPoint";
            this.colPoint.Resizable = System.Windows.Forms.DataGridViewTriState.False;
            this.colPoint.Width = 56;
            // 
            // colVoltage
            // 
            this.colVoltage.HeaderText = "Voltage";
            this.colVoltage.Name = "colVoltage";
            this.colVoltage.Resizable = System.Windows.Forms.DataGridViewTriState.False;
            this.colVoltage.Width = 56;
            // 
            // colDuration
            // 
            this.colDuration.HeaderText = "Duration";
            this.colDuration.Name = "colDuration";
            this.colDuration.Resizable = System.Windows.Forms.DataGridViewTriState.False;
            this.colDuration.Width = 56;
            // 
            // btnRemovePoint
            // 
            this.btnRemovePoint.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;
            this.btnRemovePoint.Location = new System.Drawing.Point(799, 562);
            this.btnRemovePoint.Name = "btnRemovePoint";
            this.btnRemovePoint.Size = new System.Drawing.Size(83, 23);
            this.btnRemovePoint.TabIndex = 9;
            this.btnRemovePoint.Text = "Remove Point";
            this.btnRemovePoint.UseVisualStyleBackColor = true;
            // 
            // btnAddPoint
            // 
            this.btnAddPoint.Location = new System.Drawing.Point(710, 562);
            this.btnAddPoint.Name = "btnAddPoint";
            this.btnAddPoint.Size = new System.Drawing.Size(83, 23);
            this.btnAddPoint.TabIndex = 10;
            this.btnAddPoint.Text = "Add Point";
            this.btnAddPoint.UseVisualStyleBackColor = true;
            this.btnAddPoint.Click += new System.EventHandler(this.btnAddPoint_Click);
            // 
            // chWaveform
            // 
            this.chWaveform.BackColor = System.Drawing.SystemColors.Control;
            this.chWaveform.BorderlineColor = System.Drawing.SystemColors.WindowText;
            chartArea1.Area3DStyle.LightStyle = System.Windows.Forms.DataVisualization.Charting.LightStyle.Realistic;
            chartArea1.AxisX.MajorGrid.Interval = 1000D;
            chartArea1.AxisX.MajorGrid.LineColor = System.Drawing.Color.LightGray;
            chartArea1.AxisX.MajorTickMark.Interval = 1000D;
            chartArea1.AxisX.Maximum = 5000D;
            chartArea1.AxisX.Minimum = 0D;
            chartArea1.AxisX.MinorGrid.Enabled = true;
            chartArea1.AxisX.MinorGrid.Interval = 100D;
            chartArea1.AxisX.MinorGrid.LineColor = System.Drawing.Color.WhiteSmoke;
            chartArea1.AxisX.Title = "Time (seconds)";
            chartArea1.AxisX2.IsStartedFromZero = false;
            chartArea1.AxisY.IntervalAutoMode = System.Windows.Forms.DataVisualization.Charting.IntervalAutoMode.VariableCount;
            chartArea1.AxisY.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Number;
            chartArea1.AxisY.MajorGrid.LineColor = System.Drawing.Color.LightGray;
            chartArea1.AxisY.MajorTickMark.Interval = 1D;
            chartArea1.AxisY.MajorTickMark.IntervalOffset = 0D;
            chartArea1.AxisY.MajorTickMark.IntervalOffsetType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Auto;
            chartArea1.AxisY.MajorTickMark.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Number;
            chartArea1.AxisY.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.AcrossAxis;
            chartArea1.AxisY.Maximum = 16D;
            chartArea1.AxisY.Minimum = 0D;
            chartArea1.AxisY.MinorGrid.Enabled = true;
            chartArea1.AxisY.MinorGrid.Interval = 0.25D;
            chartArea1.AxisY.MinorGrid.LineColor = System.Drawing.Color.WhiteSmoke;
            chartArea1.AxisY.MinorTickMark.Enabled = true;
            chartArea1.AxisY.MinorTickMark.Interval = 0.25D;
            chartArea1.AxisY.MinorTickMark.Size = 0.25F;
            chartArea1.AxisY.MinorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.AcrossAxis;
            chartArea1.AxisY.Title = "Voltage";
            chartArea1.Name = "ChartArea1";
            this.chWaveform.ChartAreas.Add(chartArea1);
            legend1.Enabled = false;
            legend1.Name = "Legend1";
            this.chWaveform.Legends.Add(legend1);
            this.chWaveform.Location = new System.Drawing.Point(13, 28);
            this.chWaveform.Name = "chWaveform";
            this.chWaveform.Palette = System.Windows.Forms.DataVisualization.Charting.ChartColorPalette.Excel;
            series1.ChartArea = "ChartArea1";
            series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StepLine;
            series1.Legend = "Legend1";
            series1.Name = "Series1";
            this.chWaveform.Series.Add(series1);
            this.chWaveform.Size = new System.Drawing.Size(691, 528);
            this.chWaveform.TabIndex = 5;
            this.chWaveform.Click += new System.EventHandler(this.chWaveform_Click);
            // 
            // WaveformMaker
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(894, 594);
            this.Controls.Add(this.btnAddPoint);
            this.Controls.Add(this.btnRemovePoint);
            this.Controls.Add(this.dgdPointList);
            this.Controls.Add(this.lblPointDuration);
            this.Controls.Add(this.lblPointVoltage);
            this.Controls.Add(this.chWaveform);
            this.Controls.Add(this.btnRun);
            this.Controls.Add(this.mnuStrip);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.Name = "WaveformMaker";
            this.Text = "Waveform Maker";
            this.Load += new System.EventHandler(this.WaveformMaker_Load);
            this.mnuStrip.ResumeLayout(false);
            this.mnuStrip.PerformLayout();
            ((System.ComponentModel.ISupportInitialize)(this.dgdPointList)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.chWaveform)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
        private System.Windows.Forms.MenuStrip mnuStrip;
        private System.Windows.Forms.ToolStripMenuItem mnuFile;
        private System.Windows.Forms.ToolStripMenuItem mnuFileSaveWaveform;
        private System.Windows.Forms.ToolStripMenuItem mnuFileExit;
        private System.Windows.Forms.Button btnRun;
        private System.Windows.Forms.Label lblPointVoltage;
        private System.Windows.Forms.Label lblPointDuration;
        private System.Windows.Forms.DataGridView dgdPointList;
        private System.Windows.Forms.DataGridViewTextBoxColumn colPoint;
        private System.Windows.Forms.DataGridViewTextBoxColumn colVoltage;
        private System.Windows.Forms.DataGridViewTextBoxColumn colDuration;
        private System.Windows.Forms.Button btnRemovePoint;
        private System.Windows.Forms.Button btnAddPoint;
        private System.Windows.Forms.DataVisualization.Charting.Chart chWaveform;

    }
}

1 个答案:

答案 0 :(得分:0)

您的代码运行正常但需要添加DataPoint以触发Chart显示。

这很可能是因为没有任何数据,自动设置(大多数元素的默认设置,包括ChartArea&#39; s Size)都没有任何效果从。我试了一下,在添加了一个虚拟点之后,网格和所有其他漂亮的细节都会显示得很好......:

enter image description here

如您所见清除DataPoints会再次清除图表。

如果您希望Series清除虚拟数据,可以在添加第一个数据后删除虚拟数据,也可以添加虚拟系列..