Solved

C# - Multi Splines on Chart Control.

Posted on 2013-05-17
2
1,276 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A short article about problems I had with the new location API and permissions in Marshmallow
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…
Six Sigma Control Plans

705 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