Saturday, 22 March 2014

How to bind chart control in c#

Binding the data in Micro soft Chart control, Chart in come under the Data control section. Microsoft is providing different varieties of chart control to display the statistics of data into visual form.

 Let’s just first demonstrate the important properties of Chart control, which help to build the chart.

Chrt1.ChartAreas[0].AxisX.Interval
Chrt1 - Chart name, 0 – Index of series in your chart, AxisX biding to which exis

AxisX.Interval – It defind the interval of chart;
Chart1.Series[0].SmartLabelStyle.Enabled – it enable to display the label of axis;
Chart1.Series[0].Points.DataBindXY – it bind the data to the axis;
Chart1.Series[0].ChartType – defind the chart type Bar, spiral, Pie etc;
Chart1.Series[0].IsValueShownAsLabel – showing the label value
Binding Simple bar chart;
Step 1 : Just place the chart on your page; don’t change any name till just let it be default only.

@code snippet for bind bar chart in C#

Step 2 : Write as code below to bind chart;
private void Form1_Load(object sender, EventArgs e)
        {
            BindData();
        }
        public void BindData()
        {
            List<int> yValues = new List<int>(new int[] { 20, 30, 10, 90, 50 });
            List<string> xValues = new List<string>(new string[] { "1:00", "2:00", "3:00", "4:00", "5:00" });
           chart1.Series[0].Points.DataBindXY(xValues, yValues);
        }
@Out Put;
Run application and it will appear as
1.       Binding the Pie chart, Line Chart and Point Chart;
Only need to provide the chart type on the code to bind which type of chart you need to bind.


@Code snippet for bind Pie Chart, Line Chart in c#, Point Chart in c#
public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            BindData();
        }
        public void BindData()
        {
            List<int> yValues = new List<int>(new int[] { 20, 30, 10, 90, 50 });
            List<string> xValues = new List<string>(new string[] { "1:00", "2:00", "3:00", "4:00", "5:00" });
            chart1.Series[0].IsValueShownAsLabel = true;
          //  chart1.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Pie; //  Pie chart in C#
            // chart1.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Point; // Point Chart in c#
             chart1.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line ; // Line Chart in c#
           chart1.Series[0].Points.DataBindXY(xValues, yValues);
        }


7 comments:

  1. its nice post, resolved my problem.

    ReplyDelete
    Replies
    1. really feeling good. if it helps you.

      Delete
  2. Nice information about bind chart control in c# my sincere thanks for sharing this post Please Continue to share this post
    Dot Net Training in Chennai

    ReplyDelete
  3. nice blog has been shared by you. before i read this blog i didn't have any knowledge about this but now i got some knowledge. so keep on sharing such kind of an interesting blogs.
    dot net training in chennai

    ReplyDelete

Others

You will like to read it