Solved

C# - How to export or save the Chart Control series to array?

Posted on 2013-06-02
3
1,177 Views
Last Modified: 2013-06-30
Hello everyone.
Thank you in advance for your time and attention.
My development environment: i7, W7Ult, VS2010Ult, WinForm, C# and Chart Control.
Target: Windows XP, VISTA, 7 and 8.

How to export or save the chart control series to an array? Need including the X axis labels or way to retrieve them in the future.
We have a chart with 3 series Spline, fed by the minute. By default we show the last 10 days in X axis.
#region AddNewDataPoint
    int tmStamp=14400; // 10 Days in minutes
    public void AddNewPoint()
        {
        var cX=this.chart1.ChartAreas[0];
        DateTime timeStamp=DateTime.Now;
        // Add new data point to its series.
        chart1.Series["01"].Points.AddXY(timeStamp.ToOADate(),Convert.ToDouble(i_01));
        chart1.Series["02"].Points.AddXY(timeStamp.ToOADate(),Convert.ToDouble(i_02));
        chart1.Series["03"].Points.AddXY(timeStamp.ToOADate(),Convert.ToDouble(i_03));
        // remove all points from the source series older than 1 minute.
        double removeBefore=timeStamp.AddMinutes((double)(tmStamp)*(-1)).ToOADate();
        //remove oldest values to maintain a constant number of data points
        while(chart1.Series[0].Points[0].XValue<removeBefore)
        { chart1.Series[0].Points.RemoveAt(0); }
        cX.AxisX.Minimum=chart1.Series[0].Points[0].XValue;
        cX.AxisX.Maximum=DateTime.FromOADate(chart1.Series[0].Points[0].XValue).AddMinutes(tmStamp).ToOADate();
        chart1.Invalidate();
        }
    #endregion // AddNewDataPoint

Open in new window

We create the chart with the code below.
#region Setting the Chart
    private void SetChart()
        {
        var v_Interval=86400D; // 1 Day interval in seconds.
        cX.AxisX.ScaleView.MinSize=1;
        cX.AxisX.ScaleView.MinSizeType=DateTimeIntervalType.Days;
        cX.CursorX.Interval=0;
        cX.AxisX.LabelStyle.Format="HH:mm:ss\nyyyy-MM-dd";
        cX.AxisX.LabelStyle.Interval=v_Interval;
        cX.AxisX.LabelStyle.IntervalType=System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Seconds;
        cX.AxisX.MajorGrid.Interval=v_Interval;
        cX.AxisX.MajorGrid.IntervalType=System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Seconds;
        cX.AxisX.MajorTickMark.Interval=v_Interval;
        cX.AxisX.MajorTickMark.IntervalType=System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Seconds;
        cX.AxisY.IsLabelAutoFit=false;
        cX.AxisY.IsStartedFromZero=false;
        } // Setting the Chart
    #endregion

Open in new window

0
Comment
Question by:ocaccy
  • 2
3 Comments
 
LVL 48

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 39218258
Hi,

Could the CopyTo method from the DataPointCollection Class be a solution?

Regards
0
 

Author Comment

by:ocaccy
ID: 39218443
Hi. How; have a sample ?
Regards
0
 

Author Closing Comment

by:ocaccy
ID: 39289077
Solved this way: When we launched a value in Serie Point, also launched in an Array that is saved from time to time.

Best regards,
ocaccy
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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
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 …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

706 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

18 Experts available now in Live!

Get 1:1 Help Now