Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Charting in .NET 4

, 19 Sep 2012 CPOL
Introduction to Charts in .NET 4
Charting-noexe.zip
WindowsFormsApplication1
WindowsFormsApplication1
Properties
DataSources
System.Windows.Forms.DataVisualization.Charting.Annotation.datasource
System.Windows.Forms.DataVisualization.Charting.AnnotationCollection.datasource
System.Windows.Forms.DataVisualization.Charting.AnnotationGroup.datasource
System.Windows.Forms.DataVisualization.Charting.AnnotationPathPoint.datasource
System.Windows.Forms.DataVisualization.Charting.AnnotationPathPointCollection.datasource
System.Windows.Forms.DataVisualization.Charting.AnnotationPositionChangingEventArgs.datasource
System.Windows.Forms.DataVisualization.Charting.AnnotationSmartLabelStyle.datasource
System.Windows.Forms.DataVisualization.Charting.AnovaResult.datasource
System.Windows.Forms.DataVisualization.Charting.ArrowAnnotation.datasource
System.Windows.Forms.DataVisualization.Charting.Axis.datasource
System.Windows.Forms.DataVisualization.Charting.AxisScaleBreakStyle.datasource
System.Windows.Forms.DataVisualization.Charting.AxisScaleView.datasource
System.Windows.Forms.DataVisualization.Charting.AxisScrollBar.datasource
System.Windows.Forms.DataVisualization.Charting.Border3DAnnotation.datasource
System.Windows.Forms.DataVisualization.Charting.BorderSkin.datasource
System.Windows.Forms.DataVisualization.Charting.CalloutAnnotation.datasource
System.Windows.Forms.DataVisualization.Charting.Chart.datasource
System.Windows.Forms.DataVisualization.Charting.ChartArea.datasource
System.Windows.Forms.DataVisualization.Charting.ChartArea3DStyle.datasource
System.Windows.Forms.DataVisualization.Charting.ChartAreaCollection.datasource
System.Windows.Forms.DataVisualization.Charting.ChartElement.datasource
System.Windows.Forms.DataVisualization.Charting.ChartElementOutline.datasource
System.Windows.Forms.DataVisualization.Charting.ChartGraphics.datasource
System.Windows.Forms.DataVisualization.Charting.ChartNamedElement.datasource
System.Windows.Forms.DataVisualization.Charting.ChartPaintEventArgs.datasource
System.Windows.Forms.DataVisualization.Charting.ChartSerializer.datasource
System.Windows.Forms.DataVisualization.Charting.Cursor.datasource
System.Windows.Forms.DataVisualization.Charting.CursorEventArgs.datasource
System.Windows.Forms.DataVisualization.Charting.CustomizeLegendEventArgs.datasource
System.Windows.Forms.DataVisualization.Charting.CustomLabel.datasource
System.Windows.Forms.DataVisualization.Charting.CustomLabelsCollection.datasource
System.Windows.Forms.DataVisualization.Charting.CustomProperties.datasource
System.Windows.Forms.DataVisualization.Charting.DataFormula.datasource
System.Windows.Forms.DataVisualization.Charting.DataManipulator.datasource
System.Windows.Forms.DataVisualization.Charting.DataPoint.datasource
System.Windows.Forms.DataVisualization.Charting.DataPointCollection.datasource
System.Windows.Forms.DataVisualization.Charting.DataPointComparer.datasource
System.Windows.Forms.DataVisualization.Charting.DataPointCustomProperties.datasource
System.Windows.Forms.DataVisualization.Charting.ElementPosition.datasource
System.Windows.Forms.DataVisualization.Charting.EllipseAnnotation.datasource
System.Windows.Forms.DataVisualization.Charting.FormatNumberEventArgs.datasource
System.Windows.Forms.DataVisualization.Charting.FTestResult.datasource
System.Windows.Forms.DataVisualization.Charting.Grid.datasource
System.Windows.Forms.DataVisualization.Charting.HitTestResult.datasource
System.Windows.Forms.DataVisualization.Charting.HorizontalLineAnnotation.datasource
System.Windows.Forms.DataVisualization.Charting.IDataPointFilter.datasource
System.Windows.Forms.DataVisualization.Charting.ImageAnnotation.datasource
System.Windows.Forms.DataVisualization.Charting.LabelStyle.datasource
System.Windows.Forms.DataVisualization.Charting.Legend.datasource
System.Windows.Forms.DataVisualization.Charting.LegendCell.datasource
System.Windows.Forms.DataVisualization.Charting.LegendCellCollection.datasource
System.Windows.Forms.DataVisualization.Charting.LegendCellColumn.datasource
System.Windows.Forms.DataVisualization.Charting.LegendCellColumnCollection.datasource
System.Windows.Forms.DataVisualization.Charting.LegendCollection.datasource
System.Windows.Forms.DataVisualization.Charting.LegendItem.datasource
System.Windows.Forms.DataVisualization.Charting.LegendItemsCollection.datasource
System.Windows.Forms.DataVisualization.Charting.LineAnnotation.datasource
System.Windows.Forms.DataVisualization.Charting.Margins.datasource
System.Windows.Forms.DataVisualization.Charting.NamedImage.datasource
System.Windows.Forms.DataVisualization.Charting.NamedImagesCollection.datasource
System.Windows.Forms.DataVisualization.Charting.Point3D.datasource
System.Windows.Forms.DataVisualization.Charting.PolygonAnnotation.datasource
System.Windows.Forms.DataVisualization.Charting.PolylineAnnotation.datasource
System.Windows.Forms.DataVisualization.Charting.PrintingManager.datasource
System.Windows.Forms.DataVisualization.Charting.RectangleAnnotation.datasource
System.Windows.Forms.DataVisualization.Charting.ScrollBarEventArgs.datasource
System.Windows.Forms.DataVisualization.Charting.Series.datasource
System.Windows.Forms.DataVisualization.Charting.SeriesCollection.datasource
System.Windows.Forms.DataVisualization.Charting.SmartLabelStyle.datasource
System.Windows.Forms.DataVisualization.Charting.StatisticFormula.datasource
System.Windows.Forms.DataVisualization.Charting.StripLine.datasource
System.Windows.Forms.DataVisualization.Charting.StripLinesCollection.datasource
System.Windows.Forms.DataVisualization.Charting.TextAnnotation.datasource
System.Windows.Forms.DataVisualization.Charting.TickMark.datasource
System.Windows.Forms.DataVisualization.Charting.Title.datasource
System.Windows.Forms.DataVisualization.Charting.TitleCollection.datasource
System.Windows.Forms.DataVisualization.Charting.ToolTipEventArgs.datasource
System.Windows.Forms.DataVisualization.Charting.TTestResult.datasource
System.Windows.Forms.DataVisualization.Charting.VerticalLineAnnotation.datasource
System.Windows.Forms.DataVisualization.Charting.ViewEventArgs.datasource
System.Windows.Forms.DataVisualization.Charting.ZTestResult.datasource
Settings.settings
WindowsFormsApplication1.suo
Charting.zip
bin
Release
WindowsFormsApplication1.exe
System.Windows.Forms.DataVisualization.Charting.Annotation.datasource
System.Windows.Forms.DataVisualization.Charting.AnnotationCollection.datasource
System.Windows.Forms.DataVisualization.Charting.AnnotationGroup.datasource
System.Windows.Forms.DataVisualization.Charting.AnnotationPathPoint.datasource
System.Windows.Forms.DataVisualization.Charting.AnnotationPathPointCollection.datasource
System.Windows.Forms.DataVisualization.Charting.AnnotationPositionChangingEventArgs.datasource
System.Windows.Forms.DataVisualization.Charting.AnnotationSmartLabelStyle.datasource
System.Windows.Forms.DataVisualization.Charting.AnovaResult.datasource
System.Windows.Forms.DataVisualization.Charting.ArrowAnnotation.datasource
System.Windows.Forms.DataVisualization.Charting.Axis.datasource
System.Windows.Forms.DataVisualization.Charting.AxisScaleBreakStyle.datasource
System.Windows.Forms.DataVisualization.Charting.AxisScaleView.datasource
System.Windows.Forms.DataVisualization.Charting.AxisScrollBar.datasource
System.Windows.Forms.DataVisualization.Charting.Border3DAnnotation.datasource
System.Windows.Forms.DataVisualization.Charting.BorderSkin.datasource
System.Windows.Forms.DataVisualization.Charting.CalloutAnnotation.datasource
System.Windows.Forms.DataVisualization.Charting.Chart.datasource
System.Windows.Forms.DataVisualization.Charting.ChartArea.datasource
System.Windows.Forms.DataVisualization.Charting.ChartArea3DStyle.datasource
System.Windows.Forms.DataVisualization.Charting.ChartAreaCollection.datasource
System.Windows.Forms.DataVisualization.Charting.ChartElement.datasource
System.Windows.Forms.DataVisualization.Charting.ChartElementOutline.datasource
System.Windows.Forms.DataVisualization.Charting.ChartGraphics.datasource
System.Windows.Forms.DataVisualization.Charting.ChartNamedElement.datasource
System.Windows.Forms.DataVisualization.Charting.ChartPaintEventArgs.datasource
System.Windows.Forms.DataVisualization.Charting.ChartSerializer.datasource
System.Windows.Forms.DataVisualization.Charting.Cursor.datasource
System.Windows.Forms.DataVisualization.Charting.CursorEventArgs.datasource
System.Windows.Forms.DataVisualization.Charting.CustomizeLegendEventArgs.datasource
System.Windows.Forms.DataVisualization.Charting.CustomLabel.datasource
System.Windows.Forms.DataVisualization.Charting.CustomLabelsCollection.datasource
System.Windows.Forms.DataVisualization.Charting.CustomProperties.datasource
System.Windows.Forms.DataVisualization.Charting.DataFormula.datasource
System.Windows.Forms.DataVisualization.Charting.DataManipulator.datasource
System.Windows.Forms.DataVisualization.Charting.DataPoint.datasource
System.Windows.Forms.DataVisualization.Charting.DataPointCollection.datasource
System.Windows.Forms.DataVisualization.Charting.DataPointComparer.datasource
System.Windows.Forms.DataVisualization.Charting.DataPointCustomProperties.datasource
System.Windows.Forms.DataVisualization.Charting.ElementPosition.datasource
System.Windows.Forms.DataVisualization.Charting.EllipseAnnotation.datasource
System.Windows.Forms.DataVisualization.Charting.FormatNumberEventArgs.datasource
System.Windows.Forms.DataVisualization.Charting.FTestResult.datasource
System.Windows.Forms.DataVisualization.Charting.Grid.datasource
System.Windows.Forms.DataVisualization.Charting.HitTestResult.datasource
System.Windows.Forms.DataVisualization.Charting.HorizontalLineAnnotation.datasource
System.Windows.Forms.DataVisualization.Charting.IDataPointFilter.datasource
System.Windows.Forms.DataVisualization.Charting.ImageAnnotation.datasource
System.Windows.Forms.DataVisualization.Charting.LabelStyle.datasource
System.Windows.Forms.DataVisualization.Charting.Legend.datasource
System.Windows.Forms.DataVisualization.Charting.LegendCell.datasource
System.Windows.Forms.DataVisualization.Charting.LegendCellCollection.datasource
System.Windows.Forms.DataVisualization.Charting.LegendCellColumn.datasource
System.Windows.Forms.DataVisualization.Charting.LegendCellColumnCollection.datasource
System.Windows.Forms.DataVisualization.Charting.LegendCollection.datasource
System.Windows.Forms.DataVisualization.Charting.LegendItem.datasource
System.Windows.Forms.DataVisualization.Charting.LegendItemsCollection.datasource
System.Windows.Forms.DataVisualization.Charting.LineAnnotation.datasource
System.Windows.Forms.DataVisualization.Charting.Margins.datasource
System.Windows.Forms.DataVisualization.Charting.NamedImage.datasource
System.Windows.Forms.DataVisualization.Charting.NamedImagesCollection.datasource
System.Windows.Forms.DataVisualization.Charting.Point3D.datasource
System.Windows.Forms.DataVisualization.Charting.PolygonAnnotation.datasource
System.Windows.Forms.DataVisualization.Charting.PolylineAnnotation.datasource
System.Windows.Forms.DataVisualization.Charting.PrintingManager.datasource
System.Windows.Forms.DataVisualization.Charting.RectangleAnnotation.datasource
System.Windows.Forms.DataVisualization.Charting.ScrollBarEventArgs.datasource
System.Windows.Forms.DataVisualization.Charting.Series.datasource
System.Windows.Forms.DataVisualization.Charting.SeriesCollection.datasource
System.Windows.Forms.DataVisualization.Charting.SmartLabelStyle.datasource
System.Windows.Forms.DataVisualization.Charting.StatisticFormula.datasource
System.Windows.Forms.DataVisualization.Charting.StripLine.datasource
System.Windows.Forms.DataVisualization.Charting.StripLinesCollection.datasource
System.Windows.Forms.DataVisualization.Charting.TextAnnotation.datasource
System.Windows.Forms.DataVisualization.Charting.TickMark.datasource
System.Windows.Forms.DataVisualization.Charting.Title.datasource
System.Windows.Forms.DataVisualization.Charting.TitleCollection.datasource
System.Windows.Forms.DataVisualization.Charting.ToolTipEventArgs.datasource
System.Windows.Forms.DataVisualization.Charting.TTestResult.datasource
System.Windows.Forms.DataVisualization.Charting.VerticalLineAnnotation.datasource
System.Windows.Forms.DataVisualization.Charting.ViewEventArgs.datasource
System.Windows.Forms.DataVisualization.Charting.ZTestResult.datasource
Settings.settings
WindowsFormsApplication1.suo
ChartingExe.zip
WindowsFormsApplication1.exe
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting ;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            comboBoxChartType.DataSource = System.Enum.GetValues(typeof(SeriesChartType));
            
        }


        /// <summary>
        /// Validate the user input for integer.
        /// </summary>
        /// <returns>True if all the user input contains number.</returns>
        private bool DataPointOK()
        {
            int result = 0;
            if (Int32.TryParse(txtX1.Text.Trim(), out result) ||
                Int32.TryParse(txtX2.Text.Trim(), out result) ||
                Int32.TryParse(txtX3.Text.Trim(), out result) ||
                Int32.TryParse(txtX4.Text.Trim(), out result) ||
                Int32.TryParse(txtX5.Text.Trim(), out result) ||
                Int32.TryParse(txtY1.Text.Trim(), out result) ||
                Int32.TryParse(txtY2.Text.Trim(), out result) ||
                Int32.TryParse(txtY3.Text.Trim(), out result) ||
                Int32.TryParse(txtY4.Text.Trim(), out result) ||
                Int32.TryParse(txtY5.Text.Trim(), out result))
            {
                return true;
            }

            MessageBox.Show("Enter only numbers for DataPoints");
            return false;
        }

        private void btnPlotChart_Click(object sender, EventArgs e)
        {
            DynamicChart.Series["UserDataSeries"].Points.Clear();
            DynamicChart.Series["UserDataSeries"].ChartType = (SeriesChartType)comboBoxChartType.SelectedItem;

            if (DataPointOK())
            {
                DynamicChart.Series["UserDataSeries"].Points.Add(new DataPoint(Convert.ToInt32(txtX1.Text), Convert.ToInt32(txtY1.Text)));
                DynamicChart.Series["UserDataSeries"].Points.Add(new DataPoint(Convert.ToInt32(txtX2.Text), Convert.ToInt32(txtY2.Text)));
                DynamicChart.Series["UserDataSeries"].Points.Add(new DataPoint(Convert.ToInt32(txtX3.Text), Convert.ToInt32(txtY3.Text)));
                DynamicChart.Series["UserDataSeries"].Points.Add(new DataPoint(Convert.ToInt32(txtX4.Text), Convert.ToInt32(txtY4.Text)));
                DynamicChart.Series["UserDataSeries"].Points.Add(new DataPoint(Convert.ToInt32(txtX5.Text), Convert.ToInt32(txtY5.Text)));

            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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

Share

About the Author

Trilok Arora

United States United States
No Biography provided

| Advertise | Privacy | Mobile
Web02 | 2.8.141022.2 | Last Updated 19 Sep 2012
Article Copyright 2012 by Trilok Arora
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid