There are a couple things that you're going to need to do to get this all working the way you want.
It's also not entirely clear what you mean when you say 'dynamic' - sometimes I would take that to mean that you want the page to react to user input, after it has been rendered. If that were the case then you'll have to sort out your UI and build some sort of API endpoint to serve your data for AJAX requests. But, I'm not sure that's what you mean. This approach is certainly possible, but you have to solve the other things to start with, so let's start with those.
First, and this is what your question seems to be about, is getting the data in the format you want. This means:
- running the query
- having the results 'grouped' by month
- summing result totals by group
There are 3 places you could do this, so that would be the first thing to know. Do you prefer to do the data-structuring in:
- the query (done by the database - depends your server)
- in Laravel - using Collections (this would be my approach - "server-side")
- in Javascript - (may be the most 'dynamic' - but depends on you comfort level programming in JS and what libraries you intend to use: {jQuery, Lodash, Vue,...})
So maybe some decisions first about that, before we start programming...