Skip to content
Snippets Groups Projects
Commit 5e004cd4 authored by MarcusStorvangJonassen's avatar MarcusStorvangJonassen
Browse files

Added LineChart() as a supplement for BarChart() in ActivityHistoryPage

parent 3bf27b6d
No related branches found
No related tags found
1 merge request!33Frontend ui
......@@ -35,7 +35,7 @@
FontAttributes="Bold"
HorizontalOptions="Center"/>
<Label Text="Graf over Ugentlige Skridt:"
<Label Text="Søjlediagram for Ugentlige Skridt:"
FontSize="20"
HorizontalOptions="Center"/>
......@@ -43,10 +43,10 @@
HeightRequest="400"
WidthRequest="300"/>
<VerticalStackLayout Padding="5"
Spacing="10">
<Label Text="Farveindikator:"
<VerticalStackLayout Padding="10"
Spacing="20">
<Label Text="Farveindikatorer:"
FontSize="20"
HorizontalOptions="Center"/>
......@@ -124,6 +124,14 @@
</VerticalStackLayout>
</HorizontalStackLayout>
</VerticalStackLayout>
<Label Text="Linjediagram for Ugentlige Skridt:"
FontSize="20"
HorizontalOptions="Center"/>
<chart:ChartView x:Name="LineChart"
HeightRequest="400"
WidthRequest="300"/>
<Label Text="Samlet Skridt i denne uge:"
FontSize="20"
......
......@@ -4,6 +4,7 @@ using Microcharts.Maui;
using SkiaSharp;
using System.Collections.Generic;
using Microsoft.Maui.Controls;
using Microcharts;
namespace BeSafePlus
{
......@@ -26,10 +27,14 @@ namespace BeSafePlus
e.PropertyName == nameof(ActivityHistoryViewModel.AccumulatedSteps))
{
LoadChart();
LoadLineChart();
}
};
LoadChart();
LoadLineChart();
}
protected override async void OnAppearing()
{
......@@ -42,6 +47,8 @@ namespace BeSafePlus
_viewModel.AccumulatedSteps = await _viewModel.GetStepCount();
LoadChart();
LoadLineChart();
}
private async void LoadChart()
{
......@@ -91,6 +98,47 @@ namespace BeSafePlus
MaxValue = stepGoal
};
}
private async void LoadLineChart()
{
if (_viewModel?.WeeklyStepData == null || !_viewModel.WeeklyStepData.Any()) return;
var entries = new List<Microcharts.ChartEntry>();
DateTime today = DateTime.Now.Date;
foreach (var stepData in _viewModel.WeeklyStepData)
{
if (DateTime.TryParse(stepData.Date, out DateTime stepDate))
{
int dayIndex = (int)stepDate.DayOfWeek;
// Konverter dagIndex til dansk ugedag
string dayName = DaysOfWeek[dayIndex == 0 ? 6 : dayIndex - 1];
bool isToday = stepDate.Date == today;
entries.Add(new Microcharts.ChartEntry(stepData.Steps)
{
Label = isToday ? $"*{dayName}" : dayName, // Fremhæv dagens dag med *
ValueLabel = $"{stepData.Steps}",
Color = SKColors.Blue,
TextColor = SKColors.Black,
ValueLabelColor = SKColors.Black
});
}
}
LineChart.Chart = new Microcharts.LineChart
{
Entries = entries,
LineMode = Microcharts.LineMode.Straight,
BackgroundColor = SKColors.White,
LabelTextSize = 20,
ValueLabelTextSize = 20,
LabelColor = SKColors.Black,
MaxValue = _viewModel.StepGoal
};
}
private SKColor GetStepColor(int steps, int stepGoal)
{
if (steps == 0) return SKColors.White;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment