0

I have WPF project which handle bookings and reservations for barber-shop. When running the project and clicking the "Stats" button (ButtonThird-Click) as shown below, a chart of employee performances is displayed. I am using LiveChart wpf tools. All is good so far, but I have 2 issues:

1- X-Axis and Y-Axis should be Staff_Name and No. of Appointments. However, those are not displayed as the charting is constructed on LiveCharts library basis.

enter image description here

2- The Y-Axis (No. of Appointments) is showing fraction numbers (not integers) which is ridiculous because appointments are always 0,1,2,3,4 .... etc

If you need any further details, please let me know. Below is the coding of the method implemented in MainWindow.xaml.cs

// "Stats" button handling the Employees Performances
        private void ButtonThird_Click(object sender, RoutedEventArgs e)
        {
            MainTitle.Content = "Employee Performances";
            CollaspAllView();

            DataTable dt = new DataTable();
            string connString = "Server=localhost;Port=3306;User ID=root;Database=barberdb";
            string query = "SELECT s.staff_id, s.staff_name, COUNT(a.appointment_id) AS appointment_count FROM appointment a JOIN staff s ON a.staff_id = s.staff_id GROUP BY s.staff_id, s.staff_name ORDER BY s.staff_id";
            try
            {
                using (MySqlConnection conn = new MySqlConnection(connString))
                {
                    MySqlCommand cmd = new MySqlCommand(query, conn);
                    conn.Open();
                    MySqlDataAdapter adapter = new MySqlDataAdapter(cmd);
                    adapter.Fill(dt);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error occurred: " + ex.Message);
            }

            SeriesCollection seriesCollection = new SeriesCollection();

            foreach (DataRow row in dt.Rows)
            {
                int staffId = Convert.ToInt32(row["staff_id"]);
                string staffName = row["staff_name"].ToString();
                int numAppointments = Convert.ToInt32(row["appointment_count"]);

                seriesCollection.Add(new ColumnSeries
                {
                    Title = staffName,
                    Values = new ChartValues<int> { numAppointments },
                    DataLabels = true,
                    LabelPoint = chartPoint => string.Format("{0:N0}", chartPoint.Y)
                });
            }


            DataContext = new { SeriesCollection = seriesCollection };
            Stats.Visibility = Visibility.Visible;
        }
  • sorry i dont understand your problem, could you show a sample with some data to test (you create your series) and what is your result waited...its easier to reproduce your problem...is it a problem of double axis on Y? – Frenchy Apr 24 '23 at 15:41
  • I think the problem is the fact that AxisX does not have the text "Staff_Name" , AxisY does not have the text "No. of Appointments" and Axis Y ticks are in fractions of 0.1 rather than 1. There must be some access into the Axis to set these values, which OP is not doing explicitly. I'm not familiar with LiveCharts but I think their Github would be a more likely place to get answers. – pm101 Apr 24 '23 at 15:53
  • @Frenchy There is an image enclosed in the main question. As pm101 said, the Y-Axis of the chart is showing numbers in fractions (not integers) which is not logic to have 2.9 appointments, or 3.2 appointments done by staff. So, the X-Axis is the Staff Name and Y-Axis is the number of appointments done by those staff. The difficult part that I cannot do any implicitly here due to the fact that this method is using LiveCharts package for charting. – Musta_Jaguaari Apr 24 '23 at 16:08

0 Answers0