I have been trying to populate a graph from another class. I have already made the graph public so its accessible to the subclass. When I try to run the entire program on Visual Studio 2019. It shows no error but still the graph does not get populated at all.

I tried implementing the same code from the base class and it works but somehow it doesn't work when i run it from the subclass.

This is the method from the other class called "ClassStatistics" and the base class is called "home". "linechart" is the graph variable name that i am using and is declared in the base class - home.

Am I doing anything wrong here?

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
                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();

0 Answers