using System; using System.Collections; using System.ComponentModel; using System.Drawing; using System.Data; using System.Windows.Forms; using Nevron.Dom; using Nevron.GraphicsCore; using Nevron.Editors; using Nevron.Chart; namespace Nevron.Examples.Chart.WinForm { public class NStretchMarginModeUC : NExampleBaseUC { private NChart m_Chart; public NLineSeries m_Line1; public NLineSeries m_Line2; private int m_nCounter; private bool m_bUpdating; private Nevron.UI.WinForm.Controls.NButton ResetButton; private System.Windows.Forms.Timer DataFeedTimer; private Nevron.UI.WinForm.Controls.NGroupBox groupBox1; private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label3; private System.Windows.Forms.Label label4; private System.Windows.Forms.Label label5; private System.Windows.Forms.Label label6; private System.Windows.Forms.Label BottomMarginLabel; private System.Windows.Forms.Label RightMarginLabel; private System.Windows.Forms.Label TopMarginLabel; private System.Windows.Forms.Label LeftMarginLabel; private Nevron.UI.WinForm.Controls.NHScrollBar BottomMarginScrollBar; private Nevron.UI.WinForm.Controls.NHScrollBar TopMarginScrollBar; private Nevron.UI.WinForm.Controls.NHScrollBar RightMarginScrollBar; private Nevron.UI.WinForm.Controls.NHScrollBar LeftMarginScrollBar; private Nevron.UI.WinForm.Controls.NCheckBox ShowDataLabelsCheckBox; private Nevron.UI.WinForm.Controls.NCheckBox RenderToWindowCheckBox; private Nevron.UI.WinForm.Controls.NNumericUpDown TimerSpeedNumericUpDown; private Nevron.UI.WinForm.Controls.NNumericUpDown NumberOfDataPointsUpDown; private System.ComponentModel.IContainer components = null; public NStretchMarginModeUC() { m_bUpdating = true; InitializeComponent(); m_bUpdating = false; m_nCounter = 0; } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Component Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.ResetButton = new Nevron.UI.WinForm.Controls.NButton(); this.DataFeedTimer = new System.Windows.Forms.Timer(this.components); this.label1 = new System.Windows.Forms.Label(); this.NumberOfDataPointsUpDown = new Nevron.UI.WinForm.Controls.NNumericUpDown(); this.groupBox1 = new Nevron.UI.WinForm.Controls.NGroupBox(); this.BottomMarginLabel = new System.Windows.Forms.Label(); this.RightMarginLabel = new System.Windows.Forms.Label(); this.TopMarginLabel = new System.Windows.Forms.Label(); this.LeftMarginLabel = new System.Windows.Forms.Label(); this.label4 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.label5 = new System.Windows.Forms.Label(); this.BottomMarginScrollBar = new Nevron.UI.WinForm.Controls.NHScrollBar(); this.TopMarginScrollBar = new Nevron.UI.WinForm.Controls.NHScrollBar(); this.RightMarginScrollBar = new Nevron.UI.WinForm.Controls.NHScrollBar(); this.LeftMarginScrollBar = new Nevron.UI.WinForm.Controls.NHScrollBar(); this.ShowDataLabelsCheckBox = new Nevron.UI.WinForm.Controls.NCheckBox(); this.RenderToWindowCheckBox = new Nevron.UI.WinForm.Controls.NCheckBox(); this.TimerSpeedNumericUpDown = new Nevron.UI.WinForm.Controls.NNumericUpDown(); this.label6 = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.NumberOfDataPointsUpDown)).BeginInit(); this.groupBox1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.TimerSpeedNumericUpDown)).BeginInit(); this.SuspendLayout(); // // ResetButton // this.ResetButton.Location = new System.Drawing.Point(7, 351); this.ResetButton.Name = "ResetButton"; this.ResetButton.Size = new System.Drawing.Size(156, 23); this.ResetButton.TabIndex = 0; this.ResetButton.Text = "Reset"; this.ResetButton.Click += new System.EventHandler(this.ResetButton_Click); // // DataFeedTimer // this.DataFeedTimer.Tick += new System.EventHandler(this.DataFeedTimer_Tick); // // label1 // this.label1.Location = new System.Drawing.Point(7, 302); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(156, 16); this.label1.TabIndex = 1; this.label1.Text = "Number of data points:"; // // NumberOfDataPointsUpDown // this.NumberOfDataPointsUpDown.Location = new System.Drawing.Point(7, 320); this.NumberOfDataPointsUpDown.Maximum = new System.Decimal(new int[] { 400, 0, 0, 0}); this.NumberOfDataPointsUpDown.Minimum = new System.Decimal(new int[] { 10, 0, 0, 0}); this.NumberOfDataPointsUpDown.Name = "NumberOfDataPointsUpDown"; this.NumberOfDataPointsUpDown.Size = new System.Drawing.Size(66, 20); this.NumberOfDataPointsUpDown.TabIndex = 2; this.NumberOfDataPointsUpDown.Value = new System.Decimal(new int[] { 50, 0, 0, 0}); this.NumberOfDataPointsUpDown.ValueChanged += new System.EventHandler(this.NumberOfDataPointsUpDown_ValueChanged); // // groupBox1 // this.groupBox1.Controls.Add(this.BottomMarginLabel); this.groupBox1.Controls.Add(this.RightMarginLabel); this.groupBox1.Controls.Add(this.TopMarginLabel); this.groupBox1.Controls.Add(this.LeftMarginLabel); this.groupBox1.Controls.Add(this.BottomMarginScrollBar); this.groupBox1.Controls.Add(this.TopMarginScrollBar); this.groupBox1.Controls.Add(this.RightMarginScrollBar); this.groupBox1.Controls.Add(this.LeftMarginScrollBar); this.groupBox1.Controls.Add(this.label4); this.groupBox1.Controls.Add(this.label3); this.groupBox1.Controls.Add(this.label2); this.groupBox1.Controls.Add(this.label5); this.groupBox1.Location = new System.Drawing.Point(7, 7); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(156, 175); this.groupBox1.TabIndex = 10; this.groupBox1.TabStop = false; this.groupBox1.Text = "Margins"; // // BottomMarginLabel // this.BottomMarginLabel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.BottomMarginLabel.Location = new System.Drawing.Point(116, 148); this.BottomMarginLabel.Name = "BottomMarginLabel"; this.BottomMarginLabel.Size = new System.Drawing.Size(32, 16); this.BottomMarginLabel.TabIndex = 12; // // RightMarginLabel // this.RightMarginLabel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.RightMarginLabel.Location = new System.Drawing.Point(116, 110); this.RightMarginLabel.Name = "RightMarginLabel"; this.RightMarginLabel.Size = new System.Drawing.Size(32, 16); this.RightMarginLabel.TabIndex = 11; // // TopMarginLabel // this.TopMarginLabel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.TopMarginLabel.Location = new System.Drawing.Point(116, 72); this.TopMarginLabel.Name = "TopMarginLabel"; this.TopMarginLabel.Size = new System.Drawing.Size(32, 16); this.TopMarginLabel.TabIndex = 10; // // LeftMarginLabel // this.LeftMarginLabel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.LeftMarginLabel.Location = new System.Drawing.Point(116, 34); this.LeftMarginLabel.Name = "LeftMarginLabel"; this.LeftMarginLabel.Size = new System.Drawing.Size(32, 16); this.LeftMarginLabel.TabIndex = 9; // // label4 // this.label4.Location = new System.Drawing.Point(8, 132); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(47, 16); this.label4.TabIndex = 8; this.label4.Text = "Bottom:"; // // label3 // this.label3.Location = new System.Drawing.Point(8, 94); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(47, 16); this.label3.TabIndex = 7; this.label3.Text = "Right:"; // // label2 // this.label2.Location = new System.Drawing.Point(8, 56); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(47, 16); this.label2.TabIndex = 6; this.label2.Text = "Top:"; // // label5 // this.label5.Location = new System.Drawing.Point(8, 19); this.label5.Name = "label5"; this.label5.Size = new System.Drawing.Size(47, 16); this.label5.TabIndex = 5; this.label5.Text = "Left:"; // // BottomMarginScrollBar // this.BottomMarginScrollBar.Location = new System.Drawing.Point(8, 148); this.BottomMarginScrollBar.Maximum = 110; this.BottomMarginScrollBar.Name = "BottomMarginScrollBar"; this.BottomMarginScrollBar.Size = new System.Drawing.Size(100, 16); this.BottomMarginScrollBar.TabIndex = 3; this.BottomMarginScrollBar.ValueChanged += new Nevron.UI.WinForm.Controls.ScrollBarEventHandler(this.BottomMarginScrollBar_Scroll); // // TopMarginScrollBar // this.TopMarginScrollBar.Location = new System.Drawing.Point(8, 72); this.TopMarginScrollBar.Maximum = 110; this.TopMarginScrollBar.Name = "TopMarginScrollBar"; this.TopMarginScrollBar.Size = new System.Drawing.Size(100, 16); this.TopMarginScrollBar.TabIndex = 1; this.TopMarginScrollBar.ValueChanged += new Nevron.UI.WinForm.Controls.ScrollBarEventHandler(this.TopMarginScrollBar_Scroll); // // RightMarginScrollBar // this.RightMarginScrollBar.Location = new System.Drawing.Point(8, 110); this.RightMarginScrollBar.Maximum = 110; this.RightMarginScrollBar.Name = "RightMarginScrollBar"; this.RightMarginScrollBar.Size = new System.Drawing.Size(100, 16); this.RightMarginScrollBar.TabIndex = 2; this.RightMarginScrollBar.ValueChanged += new Nevron.UI.WinForm.Controls.ScrollBarEventHandler(this.RightMarginScrollBar_Scroll); // // LeftMarginScrollBar // this.LeftMarginScrollBar.Location = new System.Drawing.Point(8, 34); this.LeftMarginScrollBar.Maximum = 110; this.LeftMarginScrollBar.Name = "LeftMarginScrollBar"; this.LeftMarginScrollBar.Size = new System.Drawing.Size(100, 16); this.LeftMarginScrollBar.TabIndex = 0; this.LeftMarginScrollBar.ValueChanged += new Nevron.UI.WinForm.Controls.ScrollBarEventHandler(this.LeftMarginScrollBar_Scroll); // // ShowDataLabelsCheckBox // this.ShowDataLabelsCheckBox.Location = new System.Drawing.Point(7, 190); this.ShowDataLabelsCheckBox.Name = "ShowDataLabelsCheckBox"; this.ShowDataLabelsCheckBox.Size = new System.Drawing.Size(156, 19); this.ShowDataLabelsCheckBox.TabIndex = 11; this.ShowDataLabelsCheckBox.Text = "Show Data Labels"; this.ShowDataLabelsCheckBox.CheckedChanged += new System.EventHandler(this.ShowDataLabelsCheckBox_CheckedChanged); // // RenderToWindowCheckBox // this.RenderToWindowCheckBox.Location = new System.Drawing.Point(7, 212); this.RenderToWindowCheckBox.Name = "RenderToWindowCheckBox"; this.RenderToWindowCheckBox.Size = new System.Drawing.Size(156, 19); this.RenderToWindowCheckBox.TabIndex = 12; this.RenderToWindowCheckBox.Text = "Render to window"; this.RenderToWindowCheckBox.CheckedChanged += new System.EventHandler(this.RenderToWindowCheckBox_CheckedChanged); // // TimerSpeedNumericUpDown // this.TimerSpeedNumericUpDown.Location = new System.Drawing.Point(7, 263); this.TimerSpeedNumericUpDown.Maximum = new System.Decimal(new int[] { 1000, 0, 0, 0}); this.TimerSpeedNumericUpDown.Minimum = new System.Decimal(new int[] { 1, 0, 0, 0}); this.TimerSpeedNumericUpDown.Name = "TimerSpeedNumericUpDown"; this.TimerSpeedNumericUpDown.Size = new System.Drawing.Size(63, 20); this.TimerSpeedNumericUpDown.TabIndex = 21; this.TimerSpeedNumericUpDown.Value = new System.Decimal(new int[] { 10, 0, 0, 0}); this.TimerSpeedNumericUpDown.ValueChanged += new System.EventHandler(this.TimerSpeedNumericUpDown_ValueChanged); // // label6 // this.label6.Location = new System.Drawing.Point(7, 244); this.label6.Name = "label6"; this.label6.Size = new System.Drawing.Size(156, 15); this.label6.TabIndex = 20; this.label6.Text = "Timer speed (ms):"; // // NStretchMarginModeUC // this.Controls.Add(this.TimerSpeedNumericUpDown); this.Controls.Add(this.label6); this.Controls.Add(this.RenderToWindowCheckBox); this.Controls.Add(this.ShowDataLabelsCheckBox); this.Controls.Add(this.groupBox1); this.Controls.Add(this.NumberOfDataPointsUpDown); this.Controls.Add(this.label1); this.Controls.Add(this.ResetButton); this.Name = "NStretchMarginModeUC"; this.Size = new System.Drawing.Size(172, 383); ((System.ComponentModel.ISupportInitialize)(this.NumberOfDataPointsUpDown)).EndInit(); this.groupBox1.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.TimerSpeedNumericUpDown)).EndInit(); this.ResumeLayout(false); } #endregion public override void Initialize() { base.Initialize(); nChartControl1.Legends.Clear(); // set a chart title NLabel title = nChartControl1.Labels.AddHeader("Stretch margin strategy, plotting real time data"); title.TextStyle.FontStyle = new NFontStyle("Times New Roman", 16, FontStyle.Italic); title.TextStyle.FillStyle = new NColorFillStyle(Color.Navy); title.ContentAlignment = ContentAlignment.BottomCenter; title.Location = new NPointL(new NLength(50, NRelativeUnit.ParentPercentage), new NLength(2, NRelativeUnit.ParentPercentage)); // setup chart m_Chart = nChartControl1.Charts[0]; m_Chart.Projection.SetPredefinedProjection(PredefinedProjection.Orthogonal); m_Chart.BoundsMode = BoundsMode.None; m_Chart.Location = new NPointL(new NLength(10, NRelativeUnit.ParentPercentage), new NLength(15, NRelativeUnit.ParentPercentage)); m_Chart.Size = new NSizeL(new NLength(80, NRelativeUnit.ParentPercentage), new NLength(80, NRelativeUnit.ParentPercentage)); m_Chart.Wall(ChartWallType.Left).Width = 0.0f; // set the Y axis range to be from -200 to 200 m_Chart.Axis(StandardAxis.PrimaryY).View = new NRangeAxisView(new NRange1DD(-200, 200)); m_Chart.Axis(StandardAxis.PrimaryX).View = new NRangeAxisView(new NRange1DD(0, 50)); NDateTimeScaleConfigurator scaleConf = new NDateTimeScaleConfigurator(); scaleConf.EnableUnitSensitiveFormatting = true; scaleConf.AutoDateTimeUnits = new NDateTimeUnit[] { NDateTimeUnit.Minute }; m_Chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = scaleConf; m_Chart.Axis(StandardAxis.Depth).Visible = false; // add the first line m_Line1 = (NLineSeries)m_Chart.Series.Add(SeriesType.Line); m_Line1.Name = "Realtime indicator 1"; m_Line1.MultiLineMode = MultiLineMode.Series; m_Line1.DataLabelStyle.Visible = false; m_Line1.Values.ValueFormatter = new NNumericValueFormatter("0.0"); m_Line1.BorderStyle.Color = Color.DarkOrange; m_Line1.BorderStyle.Width = new NLength(2, NGraphicsUnit.Pixel); m_Line1.FillStyle = new NColorFillStyle(Color.DarkOrange); // add the second line m_Line2 = (NLineSeries)m_Chart.Series.Add(SeriesType.Line); m_Line2.Name = "Realtime indicator 2"; m_Line2.MultiLineMode = MultiLineMode.Series; m_Line2.DataLabelStyle.Visible = false; m_Line2.Values.ValueFormatter = new NNumericValueFormatter("0.0"); m_Line2.BorderStyle.Color = Color.LimeGreen; m_Line2.BorderStyle.Width = new NLength(2, NGraphicsUnit.Pixel); m_Line2.FillStyle = new NColorFillStyle(Color.LimeGreen); LeftMarginScrollBar.Value = 10; TopMarginScrollBar.Value = 15; RightMarginScrollBar.Value = 90; BottomMarginScrollBar.Value = 90; TimerSpeedNumericUpDown.Value = DataFeedTimer.Interval; DataFeedTimer.Start(); } private void UpdateMargins() { if (nChartControl1 == null) return; if (m_bUpdating) return; m_bUpdating = true; int nLeft = LeftMarginScrollBar.Value; int nTop = TopMarginScrollBar.Value; int nRight = RightMarginScrollBar.Value; int nBottom = BottomMarginScrollBar.Value; if (nRight > 100) nRight = 100; if (nBottom > 100) nBottom = 100; if (nLeft > nRight) nLeft = nRight; if (nTop > nBottom) nTop = nBottom; m_Chart.Location = new NPointL(new NLength(nLeft, NRelativeUnit.ParentPercentage), new NLength(nTop, NRelativeUnit.ParentPercentage)); m_Chart.Size = new NSizeL(new NLength(nRight - nLeft, NRelativeUnit.ParentPercentage), new NLength(nBottom - nTop, NRelativeUnit.ParentPercentage)); nChartControl1.Refresh(); m_bUpdating = false; } private void UpdateMarginLabels() { if (nChartControl1 == null) return; int nLeft = LeftMarginScrollBar.Value; int nTop = TopMarginScrollBar.Value; int nRight = RightMarginScrollBar.Value; int nBottom = BottomMarginScrollBar.Value; LeftMarginLabel.Text = System.Convert.ToString(nLeft) + "%"; TopMarginLabel.Text = System.Convert.ToString(nTop) + "%"; RightMarginLabel.Text = System.Convert.ToString(nRight) + "%"; BottomMarginLabel.Text = System.Convert.ToString(nBottom) + "%"; } private void DataFeedTimer_Tick(object sender, System.EventArgs e) { double fIndicator1 = Math.Sin(m_nCounter * 10 * 3.14 / 180) * 100 * (Random.NextDouble() + 1.0); double fIndicator2 = Math.Cos(m_nCounter * 10 * 3.14 / 180) * 100 * (Random.NextDouble() + 1.0); m_Line1.Values.Add(fIndicator1); m_Line2.Values.Add(fIndicator2); DateTime test = new DateTime(1000 * m_nCounter); m_Line1.XValues.Add(test); m_Line2.XValues.Add(test); int nMaxCount = (int)NumberOfDataPointsUpDown.Value; if (m_Line1.Values.Count > nMaxCount) { m_Chart.Axis(StandardAxis.PrimaryX).View = new NRangeAxisView(new NRange1DD((double)m_nCounter / 2.0, 50 + (double)m_nCounter / 2.0)); } m_nCounter++; nChartControl1.Refresh(); } private void LeftMarginScrollBar_Scroll(object sender, Nevron.UI.WinForm.Controls.ScrollBarEventArgs e) { UpdateMargins(); UpdateMarginLabels(); } private void TopMarginScrollBar_Scroll(object sender, Nevron.UI.WinForm.Controls.ScrollBarEventArgs e) { UpdateMargins(); UpdateMarginLabels(); } private void RightMarginScrollBar_Scroll(object sender, Nevron.UI.WinForm.Controls.ScrollBarEventArgs e) { UpdateMargins(); UpdateMarginLabels(); } private void BottomMarginScrollBar_Scroll(object sender, Nevron.UI.WinForm.Controls.ScrollBarEventArgs e) { UpdateMargins(); UpdateMarginLabels(); } private void ResetButton_Click(object sender, System.EventArgs e) { m_Line1.Values.Clear(); m_Line2.Values.Clear(); //NValueTimelineScaleConfigurator dateScale = (NValueTimelineScaleConfigurator)m_Chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator; //dateScale.Labels.Clear(); m_nCounter = 0; } private void NumberOfDataPointsUpDown_ValueChanged(object sender, System.EventArgs e) { if (nChartControl1 == null) return; int nMaxCount = (int)NumberOfDataPointsUpDown.Value; if (m_Line1.Values.Count > nMaxCount) { int nCount = m_Line1.Values.Count - nMaxCount; m_Line1.Values.RemoveRange(0, nCount); m_Line2.Values.RemoveRange(0, nCount); m_Line1.XValues.RemoveRange(0, nCount); m_Line2.XValues.RemoveRange(0, nCount); } } private void ShowDataLabelsCheckBox_CheckedChanged(object sender, System.EventArgs e) { if (nChartControl1 == null) return; if (ShowDataLabelsCheckBox.Checked == true) { m_Line1.DataLabelStyle.Visible = true; m_Line1.DataLabelStyle.ArrowLength = new NLength(0); m_Line1.DataLabelStyle.ArrowStrokeStyle.Width = new NLength(0, NGraphicsUnit.Pixel); m_Line1.DataLabelStyle.TextStyle.BackplaneStyle.Shape = BackplaneShape.Ellipse; m_Line1.DataLabelStyle.TextStyle.BackplaneStyle.FillStyle = new NColorFillStyle(Color.OldLace); m_Line1.DataLabelStyle.TextStyle.BackplaneStyle.StandardFrameStyle.InnerBorderColor = Color.DarkOrange; m_Line2.DataLabelStyle.Visible = true; m_Line2.DataLabelStyle.ArrowLength = new NLength(0); m_Line2.DataLabelStyle.ArrowStrokeStyle.Width = new NLength(0, NGraphicsUnit.Pixel); m_Line2.DataLabelStyle.TextStyle.BackplaneStyle.Shape = BackplaneShape.Ellipse; m_Line2.DataLabelStyle.TextStyle.BackplaneStyle.FillStyle = new NColorFillStyle(Color.OldLace); m_Line2.DataLabelStyle.TextStyle.BackplaneStyle.StandardFrameStyle.InnerBorderColor = Color.DarkOrange; } else { m_Line1.DataLabelStyle.Visible = false; m_Line2.DataLabelStyle.Visible = false; } nChartControl1.Refresh(); } private void RenderToWindowCheckBox_CheckedChanged(object sender, System.EventArgs e) { if (nChartControl1 == null) return; if(RenderToWindowCheckBox.Checked) { nChartControl1.Settings.RenderSurface = RenderSurface.Window; } else { nChartControl1.Settings.RenderSurface = RenderSurface.Bitmap; } } private void TimerSpeedNumericUpDown_ValueChanged(object sender, System.EventArgs e) { if (nChartControl1 == null) return; DataFeedTimer.Interval = (int)TimerSpeedNumericUpDown.Value; } } }