Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

C# - Multi Splines on Chart Control.

Posted on 2013-05-17
2
Medium Priority
?
1,378 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
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

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
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 …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

810 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