using System;
using System.Drawing;
using System.Windows.Forms;
//---------------------------------
using System.Windows.Forms.DataVisualization.Charting;

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

        private void Form1_Load(object sender, EventArgs e)
        {
            // create chart area
            chart1.ChartAreas.Clear();
            ChartArea chartArea1 = new ChartArea();
            //---------------------------------------------------
            // show the chart in 3D
            chartArea1.Area3DStyle.Enable3D = true;
            //---------------------------------------------------
            // add chart area to the chart
            chart1.ChartAreas.Add(chartArea1);
            //---------------------------------------------------
            // create a data series
            Series series1 = new Series();
            Series series2 = new Series();
            //---------------------------------------------------
            // add data points to the first series
            series1.Points.Add(34);
            series1.Points.Add(64);
            series1.Points.Add(32);
            series1.Points.Add(28);
            //---------------------------------------------------
            // add data points to the second series
            series2.Points.Add(19);
            series2.Points.Add(13);
            series2.Points.Add(27);
            series2.Points.Add(6);
            //---------------------------------------------------
            // chart type
            series1.ChartType = SeriesChartType.Column;
            series2.ChartType = SeriesChartType.Column;
            //---------------------------------------------------
            // chart details
            series1.Color = Color.Red;
            series2.Color = Color.Blue;
            //---------------------------------------------------
            // show data points values as labels
            series1.IsValueShownAsLabel = true;
            series2.IsValueShownAsLabel = true;
            //---------------------------------------------------
            // add series to the chart
            chart1.Series.Clear();
            chart1.Series.Add(series1);
            chart1.Series.Add(series2);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();
            saveFileDialog1.Filter = "Picture Files (*.PNG)|*.PNG";
            //--------------------------------------------------------------------------------------
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                chart1.SaveImage(saveFileDialog1.FileName, ChartImageFormat.Png);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            // show page setup dialog
            chart1.Printing.PageSetup();
            //--------------------------------------------------
            // print preview chart
            chart1.Printing.PrintPreview();
            //--------------------------------------------------
            // print chart (without printer dialog)
            chart1.Printing.Print(false);
        }
    }
}