.

windows charting

WinSamples

the simplest example, just paste this in any method on a form – e.g. form_load():

Chart c = new Chart();
this.Controls.Add(c);
int pointCount = 200;
double yValue = 50.0;
double yValue2 = 200.0;
c.Series.Add("Series1");
c.Series.Add("Series2");
if (c.Series["Series1"].Points.Count > 0)
{
    yValue = c.Series["Series1"].Points[c.Series["Series1"].Points.Count - 1].YValues[0];
    yValue2 = c.Series["Series2"].Points[c.Series["Series1"].Points.Count - 1].YValues[0];
}
Random random = new Random();
for (int pointIndex = 0; pointIndex < pointCount; pointIndex ++)
{
    yValue = yValue + (float) (random.NextDouble()*10.0 - 5.0);
    c.Series["Series1"].Points.AddY(yValue);

    yValue2 = yValue2 + (float) (random.NextDouble()*10.0 - 5.0);
    c.Series["Series2"].Points.AddY(yValue2);
}


// Set fast line chart type
c.Dock = DockStyle.Fill;
c.Series["Series1"].ChartType = SeriesChartType.FastLine;
c.Series["Series2"].ChartType = SeriesChartType.FastLine;
ChartArea chartArea1 = new ChartArea();
chartArea1.BackColor = System.Drawing.Color.Gainsboro;
c.ChartAreas.Add(chartArea1);

One Response to this post.

  1. Posted by pietman on 29.08.13 at 9:13 pm

    public partial class FormX : Form
    {
        private double FunctionX(int x)
        {
            return System.Math.Sin(x/10F)*10;
        }
    
        public FormX()
        {
            InitializeComponent();
            Chart c = new Chart();
            this.Controls.Add(c);
            ChartArea chartArea1 = new ChartArea();
            chartArea1.BackColor = System.Drawing.Color.Gainsboro;
            c.ChartAreas.Add(chartArea1);
            c.Dock = DockStyle.Fill;
                
            int pointCount = 200;
            c.Series.Add("Series1");
            for (int pointIndex = 0; pointIndex < pointCount; pointIndex++)
            {
                var yValue = FunctionX(pointIndex);
                c.Series["Series1"].Points.AddY(yValue);
            }
    
            // Set fast line chart type
            c.Series["Series1"].ChartType = SeriesChartType.FastLine;
                
                
        }
    }
    

What's your thoughts on this?

*

Protected by WP Anti Spam