Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

C# - Multi Splines on Chart Control.

Posted on 2013-05-17
2
Medium Priority
?
1,355 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 

Accepted Solution

by:
ocaccy earned 0 total points
ID: 39176525
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
ID: 39176526
This problem is over.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Simple Linear Regression
Introduction to Processes
Suggested Courses

609 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