It was tinstaafl who put me on the right track. Click Here I did not know that .NET as of VS 2010 had a charting control!
OK, let’s get started! But the learning curve, is as always, a bit steep. MSDN does not seem to provide too much code, so I looked around on the net, but here they often make use of special graphics packages. So not much help either… After some fumbling around, I came up with the following easy ( I think ) code. Just start up a new windows form app and fill in the provided code in the Form.cs file. Enjoy!

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Graph = System.Windows.Forms.DataVisualization.Charting;

namespace WindowsFormsApplication1
    public partial class Form1 : Form
        Graph.Chart chart;

        public Form1()
            this.ClientSize = new System.Drawing.Size(750, 750);

        private void Form1_Load(object sender, EventArgs e)
            const int MaxX = 20;

            // Create new Graph
            chart = new Graph.Chart();
            chart.Location = new System.Drawing.Point(10, 10);
            chart.Size = new System.Drawing.Size(700, 700);

            // Add a chartarea called "draw", add axes to it and color the area black

            chart.ChartAreas["draw"].AxisX.Minimum = 0;
            chart.ChartAreas["draw"].AxisX.Maximum = MaxX;
            chart.ChartAreas["draw"].AxisX.Interval = 1;
            chart.ChartAreas["draw"].AxisX.MajorGrid.LineColor = Color.White;
            chart.ChartAreas["draw"].AxisX.MajorGrid.LineDashStyle = Graph.ChartDashStyle.Dash;

            chart.ChartAreas["draw"].AxisY.Minimum = -0.4;
            chart.ChartAreas["draw"].AxisY.Maximum = 1;
            chart.ChartAreas["draw"].AxisY.Interval = 0.2;
            chart.ChartAreas["draw"].AxisY.MajorGrid.LineColor = Color.White;
            chart.ChartAreas["draw"].AxisY.MajorGrid.LineDashStyle = Graph.ChartDashStyle.Dash;
            chart.ChartAreas["draw"].BackColor = Color.Black;
            // Create a new function series

            // Set the type to line      
            chart.Series["MyFunc"].ChartType = Graph.SeriesChartType.Line;

            // Color the line of the graph light green and give it a thickness of 3
            chart.Series["MyFunc"].Color = Color.LightGreen;
            chart.Series["MyFunc"].BorderWidth = 3; 

            //This function cannot include zero, and we walk through it in steps of 0.1 to add coordinates to our series
            for (double x = 0.1; x < MaxX; x += 0.1)
                chart.Series["MyFunc"].Points.AddXY(x, Math.Sin(x) / x);

            chart.Series["MyFunc"].LegendText = "sin(x) / x";

            // Create a new legend called "MyLegend".
            chart.Legends["MyLegend"].BorderColor = Color.Tomato; // I like tomato juice!

4 Years
Discussion Span
Last Post by ddanbe

Hi ddanbe,

I'm glad you found a new toy to play with. :)

You may find these examples useful: Samples Environment for Microsoft Chart ControlsClick Here

The chart control was also made available for .Net 3.5 as a separate library.

Microsoft Chart Controls for Microsoft .NET Framework 3.5Click Here

Votes + Comments
A little late, but great advise!

@RevathiSRS: Welcome to DaniWeb!
If you don't have VS2010 or later, read the post by TnTinMN(see last two lines)


Hai... Can we able to make any pictorial representation in Microsoft office 2005 .net 2.0 windows application..?? Without crystal report. please let me know.


Can you offer any advice on using this code as a basis to plot data from a SQL server?

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.