I have a form that when i submit changes the data of my charts using the dates put in:
<form action="{{route('home')}}" method="get" id="">
<div>
<label for="daterange">Date Range:</label>
<input type="date" name="StartDate" id="StartDate" class="form-control col-md-3"
value="{{isset($searchParams['StartDate']) ? $searchParams['StartDate'] : Carbon\Carbon::now()->subDays(10)->format('yy-m-d')}}"> to
<input type="date" name="EndDate" id="EndDate" class="form-control col-md-3"
value="{{isset($searchParams['EndDate']) ? $searchParams['EndDate'] : Carbon\Carbon::now()->subDays(5)->format('yy-m-d')}}">
</div>
<br>
<div>
<label for="shortcuts">shortcuts:</label>
<a class="btn btn-sm btn-white" href="#">This Week</a>
<a class="btn btn-sm btn-white" href="#">This Month</a>
</div>
<button type="submit" class="btn btn-md btn-white ml-4 mr-1">filter</button>
</form>
i have about 4 chartjs charts, I want to be able to change the date ranges of the charts without refreshing the page. I've been advised to use an ajax call but im not quite sure how to properly implement it.
var ctx = document.getElementById("Chart").getContext('2d');
var recentActivityChart = new Chart(ctx, {
type: 'bar',
data: {
labels: [
@foreach($data as $a)
'{{$a->StartDate}}',
@endforeach
],
datasets: [{
label: 'hours',
data: [
@foreach($data as $b)
'{{$b->Duration}}',
@endforeach
],
barThickness: 12,
fill: true,
backgroundColor: "rgba(54, 162, 235, 1)",
borderColor: "rgba(54, 162, 235, 1)",
borderWidth: 1,
}]
},
});