Click here to Skip to main content
13,451,773 members (48,213 online)
Click here to Skip to main content
Add your own
alternative version


11 bookmarked
Posted 19 Sep 2012

Charting in .NET 4

, 19 Sep 2012
Rate this:
Please Sign up or sign in to vote.
Introduction to Charts in .NET 4


This article gives a basic introduction to charting solutions available in .NET 4. The code will plot a different type of chart and data point depending upon user input.

Using the code

  1. The chart control is available in the toolbox. A chart control can have multiple ChartAreas, i.e., more than one chart can be displayed in a chart control. The image below gives details of all the available properties of the chart control (a picture is worth a thousand words).
  2. To plot a chart, values for X-Axis and Y-Axis can be provided by either binding data source to chart or add data-points one by one (We will use this approach).
  3. When you add data points to a series, each DataPoint instance may have exactly one X value, defined by the XValue property, and one or more Y values, each defined by the YValues property.
  4. A chart control can display lot of different types of chart like Bar, Line, Area etc.
  5. You can further modify the code to have 3 dimensional effect.
  6. This UML shows relationship among the chart class.

Chart co-ordinates

The unit of measure is a percentage of the chart picture's width and height. Coordinate values must be between 0 and 100. Relative coordinates ensure that objects remain relative to one another when a chart is resized.

// The actual code accepts 5 point user input for x-axis and y-axis, the type of chart and 
// plots the chart accordingly. 
private void btnPlotChart_Click(object sender, EventArgs e)
    DynamicChart.Series["UserDataSeries"].ChartType = (SeriesChartType)comboBoxChartType.SelectedItem;

    if (DataPointOK())
          new DataPoint(Convert.ToInt32(txtX1.Text), Convert.ToInt32(txtY1.Text)));
          new DataPoint(Convert.ToInt32(txtX2.Text), Convert.ToInt32(txtY2.Text)));
          new DataPoint(Convert.ToInt32(txtX3.Text), Convert.ToInt32(txtY3.Text)));
          new DataPoint(Convert.ToInt32(txtX4.Text), Convert.ToInt32(txtY4.Text)));
          new DataPoint(Convert.ToInt32(txtX5.Text), Convert.ToInt32(txtY5.Text)));



This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Trilok Arora
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

Questionfilter chart .net Pin
Member 1172084026-May-15 10:36
memberMember 1172084026-May-15 10:36 
QuestionHow to download your example Pin
Roberto Guerzoni20-Sep-12 20:38
memberRoberto Guerzoni20-Sep-12 20:38 
AnswerRe: How to download your example Pin
Trilok Arora21-Sep-12 10:32
memberTrilok Arora21-Sep-12 10:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180318.3 | Last Updated 19 Sep 2012
Article Copyright 2012 by Trilok Arora
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid