How can I plot recurring data on a datetime month axis in c#

179 Views Asked by At

I am working on a basic budgeting app for Windows in c#. I have an SQL table which stores a list of incomes and a table which stores expenses. In both cases the user selects whether this is a daily/weekly/monthly amount and a date for this income/expense. I have managed to create a line series chart which displays the total of all amounts per month, with Month on the x-axis, using the following code:

var query = conn.Table<incomedata>();
LineSeries IncomeLineSeries = new LineSeries();

List<DateAmountList> List1 = new List<DateAmountList>();
                for (int i = 1; i <= 12; i++)
                {
                    List1.Add(new DateAmountList() { Date = DateTimeFormatInfo.CurrentInfo.GetMonthName(i), Amount = query.AsEnumerable()
    .Where(o => CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(o.Date.Month) == DateTimeFormatInfo.CurrentInfo.GetMonthName(i)).Sum(o => (int)o.Amount) });
                }

                IncomeLineSeries.ItemsSource = List1;
                IncomeLine.Series.Add(IncomeLineSeries);

I know that I could make the user choose an end date and from that work out how many months to repeat for, but I'm stuck on how to add that amount to the total for every month and display it...

So for example you earn 100 every month for 12 months starting from January, at the moment the amount is only added to January as that is the stored datetime, how can I add 100 to every month of the DateAmountList (Amount) for as long as it recurs?

Once I have an idea of how to do it monthly, I'll apply similar logic to daily and weekly.

1

There are 1 best solutions below

0
On BEST ANSWER

I eventually figured out to do this I could populate another table with the amount stored against each month and add to the table for each month, then just add to a chart series