• Web sitemizin içeriğine ve tüm hizmetlerimize erişim sağlamak için Web sitemize kayıt olmalı ya da giriş yapmalısınız. Web sitemize üye olmak tamamen ücretsizdir.
  • Sohbetokey.com ile canlı okey oynamaya ne dersin? Hem sohbet et, hem mobil okey oyna!
  • Soru mu? Sorun mu? ''Bir Sorum Var?'' sistemimiz aktiftir. Paylaşın beraber çözüm üretelim.

Chart Kullanarak Birinci - ikinci Dereceden Denklem Grafiği Çizdirme ve Grafiği Jpeg Formatında Kayd

Üyelik Tarihi
7 Ocak 2015
Konular
4,091
Mesajlar
4,274
MFC Puanı
40
Kod:
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 System.Text.RegularExpressions;
using System.Windows.Forms.DataVisualization.Charting;

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

        private **** Form1_Load(object sender, EventArgs e)
        {
            // ilk açıldığında bu grafikleri çizdirsin.

            double y = 0;

            //Bu örneğim mesela y =x+5 grafiği çizdirecek

            for (double x = -10; x < 10; )
            {
                txtA.Text = "1"; // x in katsayısı
                txtB.Text = "5"; // sabit katsayı

                y = x + 5;

                chartBirinciDerece.Series[0].Points.AddXY(x, y);

                x += 0.1;

            }

            y = 0;

            //Bu örneğim mesela y = x ^ 2 + 5 grafiği çizdirecek

            for (double x = -10; x < 10; )
            {
                txt2A.Text = "1"; // x ^ 2 inin katsayısı
                txt2B.Text = "0"; // x in katsayısı
                txt2C.Text = "5"; // sabit katsayı

                y = Math.Pow(x, 2) + 5;

                chartIkinciDerece.Series[0].Points.AddXY(x, y);

                x += 0.1;
            }
        }
 
        private **** btnBirinciDerecedenCiz_Click(object sender, EventArgs e)
        {
            chartBirinciDerece.Series[0].Points.Clear();

            int A = 0; // xin katsayısı 

            int B = 0; // sabit değer

            try
            {
                A = int.Parse(txtA.Text);
            }
            catch (Exception)
            {
                MessageBox.Show("Hatalı Giriş...  A = 0 kabul edildi");

                A = 0;
            }

            try
            {
                B = int.Parse(txtB.Text);
            }
            catch (Exception)
            {
                MessageBox.Show("Hatalı Giriş...  B = 0 kabul edildi");

                B = 0;
            }

            double y = 0;
            //Bu örneğim mesela y = A x + B grafiği çizdirecek
            for (double x = -10; x < 10; )
            {
                y = A * x + B;
                chartBirinciDerece.Series[0].Points.AddXY(x, y);
                x += 0.1;
            }
        }

        private **** btnIkinciDerecedenCiz_Click(object sender, EventArgs e)
        {
            chartIkinciDerece.Series[0].Points.Clear();

            int A = 0; // x^2 in katsayısı 
            int B = 0; // xin katsayısı 
            int C = 0;  // sabit değer
            try
            {
                A = int.Parse(txt2A.Text);
            }
            catch (Exception)
            {
                MessageBox.Show("Hatalı Giriş...  A = 0 kabul edildi");
                A = 0;
            }

            try
            {
                B = int.Parse(txt2B.Text);
            }
            catch (Exception)
            {
                MessageBox.Show("Hatalı Giriş...  B = 0 kabul edildi");
                B = 0;
            }

            try
            {
                C = int.Parse(txt2C.Text);
            }
            catch (Exception)
            {
                MessageBox.Show("Hatalı Giriş... C = 0 kabul edildi");
                C = 0;
            }

            double y = 0;
            //Bu örneğim mesela y = A x ^ 2 + B * x + C grafiği çizdirecek
            for (double x = -10; x < 10; )
            {
                y = A * Math.Pow(x, 2) + B * x + C;
                chartIkinciDerece.Series[0].Points.AddXY(x, y);
                x += 0.1;
            }
        }

        private **** btnKadetFirst_Click(object sender, EventArgs e)
        {
            //Birinci dereceden çizdirdiğmi grafiği jpeg formatında kaydedeceğim.
            //Bunun için ilk önce SaveFileDialog sınıfından bir örnek oluşturacağım

            SaveFileDialog saveFileDialog = new SaveFileDialog();

            //Kaydet butonuna tıklanınca dosya olarak göstereceği adresi ayarlayacağım.

            saveFileDialog.InitialDirectory = Application.StartupPath;

            //hedef dosya açıldığında sadece image dosyalarını göstersin veya seçilirse hepsini göstersin

            saveFileDialog.Filter = "Image files (*.jpeg) | .jpeg | All files (*.*) | *.*";

            //hedef dosya açıldığında jpeg formatlı resim dosyalarını göstersin

            saveFileDialog.FilterIndex = 1;

            saveFileDialog.RestoreDirectory = true;

            //Dosya kaydetme penceresi açıldığında dosyanın ismini chartBirinciDerece.jpeg olarak göstereceğim

            saveFileDialog.FileName = "chartBirinciDerece.jpeg";


            //Kaydetme penceresin göster ve bu pencerede ok butonuna basılmış ise kaydetme
            //işlemini tamamla eğer ok dışında bir kontrole basılmış ise hiçbir işlem  yapma.
            
            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                Match match = Regex.Match(saveFileDialog.FileName, @"([\w:# \\]+.jpeg)", RegexOptions.IgnoreCase);

                if (match.Success)
                {
                    saveFileDialog.FileName = match.Groups[1].Value;
                }
                else
                {
                    saveFileDialog.FileName = Application.StartupPath + "\\chartBirinciDerece" + ".jpeg";
                }

                this.chartBirinciDerece.SaveImage(saveFileDialog.FileName, ChartImageFormat.Jpeg);
             
            }

            saveFileDialog.Dispose();
        }

        private **** btnKaydetSecond_Click(object sender, EventArgs e)
        {
            //Birinci dereceden çizdirdiğmi grafiği jpeg formatında kaydedeceğim.
            //Bunun için ilk önce SaveFileDialog sınıfından bir örnek oluşturacağım

            SaveFileDialog saveFileDialog = new SaveFileDialog();

            //Kaydet butonuna tıklanınca dosya olarak göstereceği adresi ayarlayacağım.

            saveFileDialog.InitialDirectory = Application.StartupPath;

            //hedef dosya açıldığında sadece image dosyalarını göstersin veya seçilirse hepsini göstersin

            saveFileDialog.Filter = "Image files (*.jpeg) | .jpeg | All files (*.*) | *.*";

            //hedef dosya açıldığında jpeg formatlı resim dosyalarını göstersin

            saveFileDialog.FilterIndex = 1;

            saveFileDialog.RestoreDirectory = true;

            //Dosya kaydetme penceresi açıldığında dosyanın ismini chartIkinciDerece.jpeg olarak göstereceğim

            saveFileDialog.FileName = "chartIkinciDerece.jpeg";


            //Kaydetme penceresin göster ve bu pencerede ok butonuna basılmış ise kaydetme
            //işlemini tamamla eğer ok dışında bir kontrole basılmış ise hiçbir işlem  yapma.

            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                Match match = Regex.Match(saveFileDialog.FileName, @"([\w:# \\]+.jpeg)", RegexOptions.IgnoreCase);

                if (match.Success)
                {
                    saveFileDialog.FileName = match.Groups[1].Value;
                }
                else
                {
                    saveFileDialog.FileName = Application.StartupPath + "\\chartIkinciDerece" + ".jpeg";
                }

                this.chartIkinciDerece.SaveImage(saveFileDialog.FileName, ChartImageFormat.Jpeg);

            }

            saveFileDialog.Dispose();
        }
   
      
    }
}
 
Üst