{
  "$schema": "https://ai.syncfusion.com/schema/registry-item.json",
  "name": "chart-real-time-chart-real-time-with-thread",
  "framework": "winforms",
  "type": "registry:component",
  "component": "Chart",
  "variant": "real-time-chart-real-time-with-thread",
  "dependencies": [
    "Syncfusion.Chart.Windows"
  ],
  "description": "Chart that updates its data on a background thread and refreshes the plot area from a Timer, demonstrating live data visualization.",
  "meta": {
    "essentialStudioRelease": "2026 Volume 3 (v35.1.37)",
    "license": "commercial-or-community",
    "licenseNote": "The Syncfusion package is licensed. The composition in this file is source you own and edit. See https://ai.syncfusion.com/licensing.md",
    "requiresLicenseKey": true,
    "requiresServerEndpoint": false,
    "platformIndex": "https://ai.syncfusion.com/winforms/llms.txt",
    "skillPack": "syncfusion/winforms-ui-components-skills",
    "docs": "https://ai.syncfusion.com/gallery/winforms/chart-real-time-chart-real-time-with-thread.md"
  },
  "files": [
    {
      "target": "src/components/chart-real-time-chart-real-time-with-thread/chart.Designer.cs",
      "content": "using System;\nusing System.Collections;\nusing System.ComponentModel;\nusing System.Drawing;\nusing System.Windows.Forms;\nusing System.Data;\nusing Syncfusion.Windows.Forms;\nusing Syncfusion.Windows.Forms.Chart;\nusing Syncfusion.Drawing;\n\nnamespace RealTimeChartRealTimeWithThread\n{\n    public partial class Form1 : MetroForm\n    {\n        #region Windows Form Designer generated code\n        /// <summary>\n        /// Required method for Designer support - do not modify\n        /// the contents of this method with the code editor.\n        /// </summary>\n        private void InitializeComponent()\n        {\n            this.chartControl1 = new Syncfusion.Windows.Forms.Chart.ChartControl();\n            this.panel1 = new System.Windows.Forms.Panel();\n            this.label40 = new System.Windows.Forms.Label();\n            this.label6 = new System.Windows.Forms.Label();\n            this.btnStop = new System.Windows.Forms.Button();\n            this.btnStart = new System.Windows.Forms.Button();\n            this.panel2 = new System.Windows.Forms.Panel();\n            this.panel1.SuspendLayout();\n            this.panel2.SuspendLayout();\n            this.SuspendLayout();\n            // \n            // chartControl1\n            // \n            this.chartControl1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) \n            | System.Windows.Forms.AnchorStyles.Left) \n            | System.Windows.Forms.AnchorStyles.Right)));\n            this.chartControl1.ChartArea.CursorLocation = new System.Drawing.Point(0, 0);\n            this.chartControl1.ChartArea.CursorReDraw = false;\n            this.chartControl1.DataSourceName = \"\";\n            this.chartControl1.IsWindowLess = false;\n            // \n            // \n            // \n            this.chartControl1.Legend.Font = new System.Drawing.Font(\"Microsoft Sans Serif\", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(161)));\n            this.chartControl1.Legend.Location = new System.Drawing.Point(85, 419);\n            this.chartControl1.Legend.Orientation = Syncfusion.Windows.Forms.Chart.ChartOrientation.Horizontal;\n            this.chartControl1.Legend.Position = Syncfusion.Windows.Forms.Chart.ChartDock.Bottom;\n            this.chartControl1.Legend.Visible = false;\n            this.chartControl1.Localize = null;\n            this.chartControl1.Location = new System.Drawing.Point(0, 0);\n            this.chartControl1.Name = \"chartControl1\";\n            this.chartControl1.PrimaryXAxis.Crossing = double.NaN;\n            this.chartControl1.PrimaryXAxis.GridLineType.ForeColor = System.Drawing.Color.Gray;\n            this.chartControl1.PrimaryXAxis.Margin = true;\n            this.chartControl1.PrimaryYAxis.Crossing = double.NaN;\n            this.chartControl1.PrimaryYAxis.Margin = true;\n            this.chartControl1.Rotation = 0.1F;\n            this.chartControl1.Size = new System.Drawing.Size(700, 492);\n            this.chartControl1.TabIndex = 0;\n            this.chartControl1.Text = \"Syncfusion Essential Chart\";\n            this.chartControl1.Tilt = 0.1F;\n            // \n            // \n            // \n            this.chartControl1.Title.Font = new System.Drawing.Font(\"Microsoft Sans Serif\", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(161)));\n            this.chartControl1.Title.Name = \"Def_title\";\n            this.chartControl1.Title.Text = \"Syncfusion Essential Chart\";\n            this.chartControl1.Titles.Add(this.chartControl1.Title);\n            // \n            // panel1\n            // \n            this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));\n            this.panel1.AutoSize = true;\n            this.panel1.BackColor = System.Drawing.Color.White;\n            this.panel1.Controls.Add(this.label40);\n            this.panel1.Controls.Add(this.label6);\n            this.panel1.Location = new System.Drawing.Point(0, 498);\n            this.panel1.Name = \"panel1\";\n            this.panel1.Size = new System.Drawing.Size(703, 85);\n            this.panel1.TabIndex = 1;\n            // \n            // label40\n            // \n            this.label40.BackColor = System.Drawing.Color.Transparent;\n            this.label40.Font = new System.Drawing.Font(\"Segoe UI\", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));\n            this.label40.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));\n            this.label40.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;\n            this.label40.Location = new System.Drawing.Point(3, 36);\n            this.label40.Name = \"label40\";\n            this.label40.Size = new System.Drawing.Size(697, 42);\n            this.label40.TabIndex = 7;\n            this.label40.Text = \"Points are added by thread for each one second. The last 20 seconds points are on\" +\n    \"ly visible in chart, other invisible points are removed from chart series to imp\" +\n    \"rove performance of chart.\\r\\n\";\n            // \n            // label6\n            // \n            this.label6.Font = new System.Drawing.Font(\"Segoe UI\", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));\n            this.label6.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));\n            this.label6.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;\n            this.label6.Location = new System.Drawing.Point(4, 3);\n            this.label6.Name = \"label6\";\n            this.label6.Size = new System.Drawing.Size(688, 26);\n            this.label6.TabIndex = 6;\n            this.label6.Text = \"Sample Description\";\n            this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;\n            // \n            // btnStop\n            // \n            this.btnStop.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))));\n            this.btnStop.FlatStyle = System.Windows.Forms.FlatStyle.Flat;\n            this.btnStop.Font = new System.Drawing.Font(\"Segoe UI\", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));\n            this.btnStop.ForeColor = System.Drawing.Color.White;\n            this.btnStop.Location = new System.Drawing.Point(48, 83);\n            this.btnStop.Name = \"btnStop\";\n            this.btnStop.Size = new System.Drawing.Size(137, 34);\n            this.btnStop.TabIndex = 1;\n            this.btnStop.Text = \"STOP\";\n            this.btnStop.UseVisualStyleBackColor = false;\n            this.btnStop.Click += new System.EventHandler(this.btnStop_Click);\n            // \n            // btnStart\n            // \n            this.btnStart.BackColor = System.Drawing.Color.Green;\n            this.btnStart.FlatStyle = System.Windows.Forms.FlatStyle.Flat;\n            this.btnStart.Font = new System.Drawing.Font(\"Segoe UI\", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));\n            this.btnStart.ForeColor = System.Drawing.Color.White;\n            this.btnStart.Location = new System.Drawing.Point(48, 36);\n            this.btnStart.Name = \"btnStart\";\n            this.btnStart.Size = new System.Drawing.Size(137, 34);\n            this.btnStart.TabIndex = 0;\n            this.btnStart.Text = \"START\";\n            this.btnStart.UseVisualStyleBackColor = false;\n            this.btnStart.Click += new System.EventHandler(this.btnStart_Click);\n            // \n            // panel2\n            // \n            this.panel2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) \n            | System.Windows.Forms.AnchorStyles.Right)));\n            this.panel2.BackColor = System.Drawing.Color.WhiteSmoke;\n            this.panel2.Controls.Add(this.btnStart);\n            this.panel2.Controls.Add(this.btnStop);\n            this.panel2.Location = new System.Drawing.Point(700, 0);\n            this.panel2.Name = \"panel2\";\n            this.panel2.Size = new System.Drawing.Size(260, 590);\n            this.panel2.TabIndex = 2;\n            // \n            // Form1\n            // \n            this.BackColor = System.Drawing.Color.White;\n            this.ClientSize = new System.Drawing.Size(958, 584);\n            this.Controls.Add(this.panel2);\n            this.Controls.Add(this.chartControl1);\n            this.Controls.Add(this.panel1);\n            this.MinimumSize = new System.Drawing.Size(553, 516);\n            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);\n            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;\n            this.Name = \"Form1\";\n            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;\n            this.Text = \"Real Time Scenario using Thread\";\n            this.Load += new System.EventHandler(this.Form1_Load);\n            this.panel1.ResumeLayout(false);\n            this.panel2.ResumeLayout(false);\n            this.ResumeLayout(false);\n            this.PerformLayout();\n\n        }\n\n        #endregion\n\n        #region Private Members\n        private Syncfusion.Windows.Forms.Chart.ChartControl chartControl1;\n        private System.ComponentModel.IContainer components;\n        private System.Windows.Forms.Panel panel1;\n        private Button btnStop;\n        private Button btnStart;\n        private Label label6;\n        private Label label40;\n        private Panel panel2;\n        DateTime lastTime = DateTime.Now;\n\n        #endregion\n\n        /// <summary>\n        /// Clean up any resources being used.\n        /// </summary>\n        protected override void Dispose(bool disposing)\n        {\n            if (disposing && (components != null))\n            {\n                components.Dispose();\n            }\n            base.Dispose(disposing);\n        }\n    }\n}\n"
    },
    {
      "target": "src/components/chart-real-time-chart-real-time-with-thread/chart.cs",
      "content": "using System;\nusing System.Drawing;\nusing System.Drawing.Drawing2D;\nusing System.Collections;\nusing System.Windows.Forms;\nusing System.Data;\nusing Syncfusion.Windows.Forms;\nusing Syncfusion.Windows.Forms.Chart;\nusing Syncfusion.Drawing;\nusing System.Threading;\n\nnamespace RealTimeChartRealTimeWithThread\n{\n    public partial class Form1 : MetroForm\n    {\n        #region Form Constructor\n\n        public Form1()\n        {\n            BorderColor = Color.FromArgb(0xFF, 0xCD, 0xCD, 0xCD);\n            BorderThickness = 3;\n            CaptionBarHeight = 75;\n            CaptionBarColor = Color.FromArgb(0xFF, 0x1B, 0xA1, 0xE2);\n            CaptionFont = new Font(\"Segoe UI\", 22.0f);\n            CaptionForeColor = Color.White;\n            CaptionAlign = HorizontalAlignment.Left;\n            ShowIcon = false;\n            CaptionButtonColor = Color.White;\n            CaptionButtonHoverColor = Color.White;\n            InitializeComponent();\n        }\n\n        #endregion\n\n        private Thread addRealData;\n        public delegate void AddDataDelegate();\n        public AddDataDelegate addDataDel;\n        private ManualResetEvent run;\n        Random rand = new Random();\n        private DateTime minValue;\n        private DateTime maxValue;\n        ThreadStart Start;\n        DateTime timeStamp = DateTime.Now;\n\n        #region Form Load\n        private void Form1_Load(object sender, System.EventArgs e)\n        {\n            //Create a new single thread to add points to chart series\n            Start = new ThreadStart(DataThreadLoop);\n            addRealData = new Thread(Start);\n            addDataDel += new AddDataDelegate(AddChartData);\n            run = new ManualResetEvent(true);\n            InitializeChart();\n            ChartAppearance.ApplyChartStyles(this.chartControl1);\n        }\n        #endregion\n\n        #region Helper Method\n        void InitializeChart()\n        {\n            minValue = timeStamp;\n            maxValue = minValue.AddSeconds(30);\n            chartControl1.Series.Clear();\n            chartControl1.PrimaryXAxis.ValueType = ChartValueType.DateTime;\n            chartControl1.PrimaryXAxis.DateTimeRange = new ChartDateTimeRange(minValue, maxValue, 10, ChartDateTimeIntervalType.Seconds);\n            chartControl1.PrimaryXAxis.DateTimeFormat = \"HH:mm:ss\";\n            this.chartControl1.ShowLegend = false;\n            ChartSeries series = new ChartSeries(\"Spline\");\n            series.Type = ChartSeriesType.Spline;\n            for (int i = 0; i <= 9; i++)\n            {\n                timeStamp = timeStamp.AddSeconds(i);\n                series.Points.Add(timeStamp, rand.Next(2, 17));\n            }\n            \n            series.Style.Border.Width = 2;\n            //series.Style.Symbol.Shape = ChartSymbolShape.Circle;\n            chartControl1.Series.Add(series);\n            \n           this.btnStart_Click(null, EventArgs.Empty);\n        }\n\n       private void DataThreadLoop()\n        {\n            try\n            {\n                while (true)\n                {\n                    run.WaitOne();\n                    // Invoke method used to interact with the chart control on the form\n                    chartControl1.Invoke(addDataDel);\n\n                    // Thread is inactive for 200ms\n                    Thread.Sleep(200);\n                }\n            }\n            catch\n            {\n                // Thread is aborted\n            }\n        }\n        /// <summary>\n        /// AddChartData Method invoked from the thread to add series points\n        /// </summary>\n        public void AddChartData()\n        {\n            timeStamp = timeStamp.AddSeconds(1);\n            foreach (ChartSeries Series in this.chartControl1.Series)\n            {\n                AddNewPoint(timeStamp, Series);\n            }\n        }\n        public void AddNewPoint(DateTime timeStamp, ChartSeries Series)\n        {\n            // Add new data point to series.\n            Series.Points.Add(timeStamp, rand.Next(3, 17));\n          \n            //// remove all points from the source series older than 30 seconds.\n            double removePointVal = timeStamp.AddSeconds((double)(30) * (-1)).ToOADate();\n\n\n            while (Series.Points[0].DateX.ToOADate() < removePointVal)\n            {\n                Series.Points.RemoveAt(0);\n            }\n            chartControl1.PrimaryXAxis.Range.Min = Series.Points[0].DateX.ToOADate();\n            chartControl1.PrimaryXAxis.Range.Max = Series.Points[0].DateX.AddSeconds(30).ToOADate();\n        }\n       \n        private void btnStart_Click(object sender, EventArgs e)\n        {\n            // Disable the Stop button on the form\n            btnStart.Enabled = false;\n            // Enable the Stop button on the form\n            btnStop.Enabled = true;       \n\n            // start worker threads.\n            if (addRealData.IsAlive == true)\n            {\n                run.Set();\n            }\n            else\n            {\n                addRealData.Start();\n            }  \n\n        }\n\n        private void btnStop_Click(object sender, EventArgs e)\n        {\n       \n\t\t\t// Suspend thread\n            if (addRealData.IsAlive == true)\n\t\t\t{\n                run.Reset();\n            }\n\n\t\t\t// Enable start button on the form\n            btnStart.Enabled = true;\n\n\t\t\t// Disable the Stop button\n            btnStop.Enabled = false;\n\n        }\n        #endregion\n\n    }\n}\n"
    }
  ]
}