I want to scale X and Y axis by considering data set in C#.
This is part of data set in .csv file
Name,Speed,Distance
Amal,20.50,100.20
Kamal,52.60,254.90
Nimal,42.00,245.00
Perera,20.30,142.00
Kasun,56.40,368.00
Piyal,45.60,784.00
Roy,45.00,521.00
Tony,25.00,36.00
Nikky,36.00,56.00
Jems,47.00,48.00
Jully,56.00,120.00
Tizz,78.00,354.00
Taly,45.00,100.00
Row,18.00,350.00
Saga,15.60,250.00
Peter,45.00,120.00
Taw,89.00,56.00
Nanny,78.60,487.00
Jumo,108.00,150.00
This is the code that I used to plot the graph.
private void Output_Load(object sender, EventArgs e)
{
List<Graph> ObservingData = new List<Graph>(); // List to store all available Graph objects from the CSV
// Loops through each lines in the CSV
foreach (string line in System.IO.File.ReadAllLines(pathToCsv).Skip(1)) // .Skip(1) is for skipping header
{
// here line stands for each line in the csv file
string[] InCsvLine = line.Split(',');
// creating an object of type Graph based on the each csv line
Graph Inst1 = new Graph();
Inst1.Speed = double.Parse(InCsvLine[1]);
Inst1.Distance= double.Parse(InCsvLine[2]);
chart1.Series["Distance"].YAxisType = AxisType.Primary;
chart1.Series["Distance"].Points.AddXY(Inst1.Speed, Inst1.Distance);
chart1.Series["Distance"].ChartType = SeriesChartType.FastLine;
ChartArea CA = chart1.ChartAreas[0];
CA.AxisX.ScaleView.Zoomable = false;
CA.AxisY.ScaleView.Zoomable = false;
CA.CursorX.AutoScroll = true;
CA.CursorX.IsUserSelectionEnabled = true;
}
}
and this is the class that store data.
class Graph
{
public string Name { get; set; } // property to store Name
public double Speed{ get; set; } // property to store Speed
public double Distance { get; set; } // property to store Distance
}
Now I want to scale this X and Y axis by considering data set in .csv
file. Scale should be under condition.
I explain that by getting an example for that. lets say in data set we have:
the Distance max = 784.00 & min = 36.00
then that Y axis should show values only from 33
to 787
(means + / - 0.3)
program should be want to get Min and Max value in .csv
file during in file read.
like wise think about X axis.
Can you tell me how I to code that? Any help very appreciated.