Я пытался заполнить график из другого класса.Я уже сделал граф общедоступным, чтобы он был доступен для подкласса.Когда я пытаюсь запустить всю программу в Visual Studio 2019. Она не показывает ошибок, но график все равно не заполняется вообще.
Я пытался реализовать тот же код из базового класса, и он работает, но как-то такне работает, когда я запускаю его из подкласса.
Это метод из другого класса с именем "ClassStatistics", а базовый класс называется "home"."linechart" - это имя переменной графа, которое я использую и объявлено в базовом классе - home.
Я что-то здесь не так делаю?
DataTable dt = new DataTable();
dt.Columns.Add("X_Value", typeof(DateTime)); //X axis of the type date.
dt.Columns.Add("Y_Value", typeof(double)); //Y axis of type double.
Console.WriteLine("Hello M");
StreamReader sr = new StreamReader(Path.GetFullPath("UserData/Logs") + "\\" + System.DateTime.Today.ToString("MM-yyyy") + "_Logs.txt"); //Path to the log file.
string line;
DayOfWeek day = DateTime.Now.DayOfWeek; //Current day of the week
int days = day - DayOfWeek.Monday; //Keeps track of the number of days left before the next week.
DateTime Start = DateTime.ParseExact(new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).ToString("dd-MM-yyyy"), "dd-MM-yyyy", CultureInfo.InvariantCulture); //First day of the month
DateTime End = DateTime.ParseExact(new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).AddMonths(1).AddDays(-1).ToString("dd-MM-yyyy"), "dd-MM-yyyy", CultureInfo.InvariantCulture); //Last day of the month
DateTime temp; //stores the date extracted from the log file.
int max = 0;
while ((line = sr.ReadLine()) != null)
{
string[] strarr = line.Split(':'); //Splits the data using ':' for '0' to store the date and '1' to store the number of errors
temp = DateTime.ParseExact(strarr[0], "dd-MM-yyyy", CultureInfo.InvariantCulture); //Extracts the date present in the array
if (temp >= Start && temp <= End) //checks if the given date lies in the same month
{
if (Convert.ToInt32(strarr[1]) > max)
max = Convert.ToInt32(strarr[1]); //Storing the maximum value of Y in max
Console.WriteLine(strarr[1]);
dt.Rows.Add(temp, strarr[1]); //Add data to the data table to show in the graph.
}
}
linechart.DataSource = dt;
linechart.Series["Error-Date"].XValueMember = "X_Value";
linechart.Series["Error-Date"].YValueMembers = "Y_Value";
linechart.Series["Error-Date"].ChartType = SeriesChartType.Line; //Defining the type of chart
linechart.ChartAreas[0].AxisY.Maximum = max; //setting the maximum value of the Y axis
//Change the line colors and grid colors of the chart of both the axes.
linechart.ChartAreas[0].AxisX.LineColor = Color.Black;
linechart.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.Black;
linechart.ChartAreas[0].AxisX.LabelStyle.ForeColor = Color.White;
linechart.ChartAreas[0].AxisX.Interval = 1;
linechart.ChartAreas[0].AxisY.LineColor = Color.Black;
linechart.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.Black;
linechart.ChartAreas[0].AxisY.LabelStyle.ForeColor = Color.White;
linechart.Series["Error-Date"].BorderWidth = 5;
if (sr != null) sr.Close();