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.
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;
}