Solved

C# - Multi Splines on Chart Control.

Posted on 2013-05-17
2
1,147 Views
Last Modified: 2013-05-17
Hi everyone.

In my app has myArray[x,5]. This myArray is populate every minute. I need add 5 Splines on the chart; one for each y in myArray. Put screenshot for viewing.
Although the values are differents, plot only this single line.
C#, VS2010 Ultimate, WinForms, not WPF.
All help is welcome, thanks in advance, ocaccy
single line spline chart
        public void AddData2_7()
            {
            DateTime timeStamp=DateTime.Now;

            foreach(Series ptSeries127 in chart2_7.Series)
                {
                AddNewPoint1227(timeStamp,ptSeries127);
                }
            }

        public void AddNewPoint1227(DateTime timeStamp,System.Windows.Forms.DataVisualization.Charting.Series ptSeries1227)
            {
            // Add new data point to its series.
            ptSeries1227.Points.AddXY(timeStamp.ToOADate(),Convert.ToDouble(a_s_Ritsu[cHR,3]));
            //ptSeries1227.Points.AddXY(timeStamp.ToOADate(),Convert.ToDouble(a_s_Ritsu[cHR,5]));
            //ptSeries1227.Points.AddXY(timeStamp.ToOADate(),Convert.ToDouble(a_s_Ritsu[cHR,7]));

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

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

            chart2_7.ChartAreas[0].AxisX.Minimum=ptSeries1227.Points[0].XValue;
            //chart2_7.ChartAreas[0].AxisX.Maximum = DateTime.FromOADate(ptSeries.Points[0].XValue).AddSeconds(60).ToOADate();
            chart2_7.ChartAreas[0].AxisX.Maximum=DateTime.FromOADate(ptSeries1227.Points[0].XValue).AddMinutes(10).ToOADate();
            chart2_7.Invalidate();
            }
void MakeChart()
	{
            #region chart2_7.Series.Add("seriesx")
            chart2_7.Series.Add("ID01");
            chart2_7.Series["ID01"].ChartArea="ChartArea1";
            chart2_7.Series["ID01"].ChartType=System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline;
            chart2_7.Series["ID01"].Color=System.Drawing.Color.Lime;
            chart2_7.Series["ID01"].Legend="Legend1";
            chart2_7.Series["ID01"].Name="ID01";

            chart2_7.Series.Add("ID02");
            chart2_7.Series["ID02"].ChartArea="ChartArea1";
            chart2_7.Series["ID02"].ChartType=System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline;
            chart2_7.Series["ID02"].Color=System.Drawing.Color.Orange;
            chart2_7.Series["ID02"].Legend="Legend1";
            chart2_7.Series["ID02"].Name="ID02";

            chart2_7.Series.Add("ID03");
            chart2_7.Series["ID03"].ChartArea="ChartArea1";
            chart2_7.Series["ID03"].ChartType=System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline;
            chart2_7.Series["ID03"].Color=System.Drawing.Color.BlueViolet;
            chart2_7.Series["ID03"].Legend="Legend1";
            chart2_7.Series["ID03"].Name="ID03";

            chart2_7.Series.Add("Warning");
            chart2_7.Series["Warning"].ChartArea="ChartArea1";
            chart2_7.Series["Warning"].ChartType=System.Windows.Forms.DataVisualization.Charting.SeriesChartType.FastLine;
            chart2_7.Series["Warning"].Color=System.Drawing.Color.Blue;
            chart2_7.Series["Warning"].Legend="Legend1";
            chart2_7.Series["Warning"].Name="Warning";

            chart2_7.Series.Add("Alarm");
            chart2_7.Series["Alarm"].ChartArea="ChartArea1";
            chart2_7.Series["Alarm"].ChartType=System.Windows.Forms.DataVisualization.Charting.SeriesChartType.FastLine;
            chart2_7.Series["Alarm"].Color=System.Drawing.Color.Red;
            chart2_7.Series["Alarm"].Legend="Legend1";
            chart2_7.Series["Alarm"].Name="Alarm";
            #endregion // chart2_7.Series.Add("seriesx")
}

Open in new window

0
Comment
Question by:ocaccy
  • 2
2 Comments
 

Accepted Solution

by:
ocaccy earned 0 total points
Comment Utility
Ok guys. The code below solved my problem.
        public void XY_AddNewPoint27()
            {
            DateTime timeStamp=DateTime.Now;
            // Add new data point to its series.
            chart2_7.Series["ID01-"].Points.AddXY(timeStamp.ToOADate(),Convert.ToDouble(a_s_Ritsu[cHR,3]));
            chart2_7.Series["ID02"].Points.AddXY(timeStamp.ToOADate(),Convert.ToDouble(a_s_Ritsu[cHR,5]));
            chart2_7.Series["ID03"].Points.AddXY(timeStamp.ToOADate(),Convert.ToDouble(a_s_Ritsu[cHR,7]));

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

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

            chart2_7.ChartAreas[0].AxisX.Minimum=chart2_7.Series[0].Points[0].XValue;
            chart2_7.ChartAreas[0].AxisX.Maximum=DateTime.FromOADate(chart2_7.Series[0].Points[0].XValue).AddMinutes(10).ToOADate();
            chart2_7.Invalidate();
            }

Open in new window

0
 

Author Closing Comment

by:ocaccy
Comment Utility
This problem is over.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now