Anda di halaman 1dari 2

using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Windows.Forms.DataVisualization.Charting;

namespace GRes2D
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog Open = new OpenFileDialog();
Open.Title = " Open Your Data hehe";
Open.Filter = "File txt|*.txt";
Open.ShowDialog();
string A = Open.FileName;
var B = File.ReadAllLines(A);
var C = (from i in B select i.Split('\t')).ToArray();
int D = (from j in C select j.Count()).Max();
var table = new DataTable();
table.Columns.AddRange(new DataColumn[] { new DataColumn("No"), new
DataColumn("AB/2 (m)"), new DataColumn("MN/2 (m) "), new DataColumn("V (mV)"), new
DataColumn("I (mA)"), new DataColumn("K (m)"), new DataColumn("Rho (Ohm.m)") });
StreamReader Data = new StreamReader(A);
string all = Data.ReadToEnd();
string[] nv = all.Split('\n');
Double[] No = new Double[nv.Length];
Double[] AB = new Double[nv.Length];
Double[] MN = new Double[nv.Length];
Double[] deltav = new Double[nv.Length];
Double[] current = new Double[nv.Length];
Double[] k = new Double[nv.Length];
Double[] Rho = new Double[nv.Length];

for (int i = 0; i < nv.Length; i++)


{
string[] allarray = nv[i].Split('\t');
No[i] = Convert.ToDouble(allarray[0]);
AB[i] = Convert.ToDouble(allarray[1]);
MN[i] = Convert.ToDouble(allarray[2]);
deltav[i] = Convert.ToDouble(allarray[3]);
current[i] = Convert.ToDouble(allarray[4]);
k[i] = Math.PI * (Math.Pow (AB[i], 2) - Math.Pow (MN[i], 2)) /
(MN[i]*2);
Rho[i] = k[i] * (deltav[i] / current[i]);
object[] row = { No[i], AB[i], MN[i], deltav[i], current[i], k[i],
Rho[i] };
table.Rows.Add(row);
}
dataGridView1.DataSource = table;
chart1.Series.Add("VES Data");
chart1.Series["VES Data"].ChartType = SeriesChartType.Line;
chart1.Series["VES Data"].Color = Color.DarkSlateBlue;
chart1.Series[0].IsVisibleInLegend = false;
chart1.ChartAreas[0].AxisX.Title = "AB/2 (m)";
chart1.ChartAreas[0].AxisY.Title = "Rho App (Ohm.m)";
chart1.ChartAreas[0].AxisX.IsLogarithmic = true;
chart1.ChartAreas[0].AxisY.IsLogarithmic = true;
chart1.ChartAreas[0].AxisX.MinorGrid.Enabled = true;
chart1.ChartAreas[0].AxisY.MinorGrid.Enabled = true;
chart1.ChartAreas[0].AxisX.MinorGrid.Interval = 1;
chart1.ChartAreas[0].AxisY.MinorGrid.Interval = 1;

for (int i = 0; i < nv.LongLength; i++)


{
chart1.Series["VES Data"].Points.AddXY(AB[i], Rho[i]);
}

private void chart1_Click(object sender, EventArgs e)


{

}
}
}

Anda mungkin juga menyukai