score:0

Accepted answer

update: the best way to this is to have use iframes. set up your form to like so

<form action="{{route('chart.home')}}" method="get" id="" target="charts">
                            <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()->subday(7)->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()->format('yy-m-d')}}">
                            </div>
                            <br>
                            <button type="submit"  class="btn btn-sm btn-white">filter</button>

where you would place your canvas, replace is with an iframe like so:

<iframe  name="charts" id="iframe" src="{{route('chart.home')}}"></iframe>

this will populate whatever you're submitting within this iframe.

in your blade of charthome.blade.php, put your chartjs. on form submission your chartjs will update and display in your iframe without reloading the page!

this version does not require ajax calls or prevent defaults so it is a lot easier to and requires less code and knowhow. for more information on iframes check out

https://developer.mozilla.org/en-us/docs/web/html/element/iframe https://css-tricks.com/snippets/html/post-data-to-an-iframe/

score:0

i can't give you code based off of what you gave me. but here's the basic principle:

  1. set up your canvas
<canvas id="mychart" width="400" height="400"></canvas>
<script>
var ctx = document.getelementbyid('mychart').getcontext('2d');

</script>
  1. have the form prevent it's default behavior - ie, don't submit.
    can i make a <button> not submit a form?

  2. have your button trigger an ajax call using jquery. jquery get is the most basic implementation for learning. check out jquery: https://api.jquery.com/jquery.get/

<button onclick="dojsfunction(ctx)">

  1. with the response data, format it in a way that your chart js can use. i'm sure that the chartjs library has a refresh or update or draw new chart type of method.

in your dojsfunction, do something like this:

$.get( "/yourchartdata", { startdate: "12-20-2020", enddate: "12-31-2020" } )
  .done(function( data ) {
    var mychart = new chart(ctx, {
type: 'bar',
data: { // all of this either gets filled in by or changed by your response data
    labels: ['red', 'blue', 'yellow', 'green', 'purple', 'orange'],
    datasets: [{
        label: '# of votes',
        data: [12, 19, 3, 5, 2, 3],
        backgroundcolor: [
            'rgba(255, 99, 132, 0.2)',
            'rgba(54, 162, 235, 0.2)',
            'rgba(255, 206, 86, 0.2)',
            'rgba(75, 192, 192, 0.2)',
            'rgba(153, 102, 255, 0.2)',
            'rgba(255, 159, 64, 0.2)'
        ],
        bordercolor: [
            'rgba(255, 99, 132, 1)',
            'rgba(54, 162, 235, 1)',
            'rgba(255, 206, 86, 1)',
            'rgba(75, 192, 192, 1)',
            'rgba(153, 102, 255, 1)',
            'rgba(255, 159, 64, 1)'
        ],
        borderwidth: 1
    }]
},
options: {
    scales: {
        yaxes: [{
            ticks: {
                beginatzero: true
            }
        }]
    }
} 

}); });

edit: here is the chartjs for drawing a new chart. hhttps://www.chartjs.org/docs/latest/


Related Query

More Query from same tag