score:0
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:
- set up your canvas
<canvas id="mychart" width="400" height="400"></canvas>
<script>
var ctx = document.getelementbyid('mychart').getcontext('2d');
</script>
have the form prevent it's default behavior - ie, don't submit.
can i make a <button> not submit a form?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)">
- 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/
Source: stackoverflow.com
Related Query
- update my chartjs form without refreshing page
- Update only Chart.js without animations and without refreshing the browser
- How to refresh chart in django without refreshing whole page
- Update chart.js after form submission and page reload
- update chart in chart js without reloading the page
- My Chartjs is not updating after setstate full code attached Reactjs Update
- Dynamically update values of a chartjs chart
- Dynamically update the options of a chart in chartjs using Javascript
- ChartJS : How to leave just points without lines
- Hide gridlines in chartjs without the drawTicks
- how to always show label in chartjs without mouseover?
- Chartjs doesn't update dataset label on tooltips
- ChartJS Update callbacks
- Update charts in chartjs and angular
- How to add ChartJS code in Html2Pdf to view image
- Chartjs export chart without html
- Chartjs in Reactjs - how can I update data dynamically?
- dynamically update the scale type of chartjs graph
- How do I add time sourced from an external source as an X axis to a ChartJS graph?
- Chartjs not working with d3 from csv source
- ChartJS update chart with multiple datasets
- ChartJS v2.6 update breaks custom line-with-area-range (stripe) chart
- Automatically update ChartJS with Knockout data-bind
- ChartJs chart won't update new values
- Why can't I update the aspectRatio within the chartjs chart?
- Chartjs tooltip out of page
- How to update a chart using VueJS and ChartJS
- Chartjs with streaming plugin: update y-range
- React Chartjs - Update Chart on interval
- Automatic update a ChartJs with SQL
More Query from same tag
- Offset Overlay Line on chart.js Graph
- Chart.js chart doesn't render when using Angular 2
- ChartJS canvas not displaying rgba colors in IE, Safari and Firefox
- How can I get access to the index of the highlighted dataset in Chart.js
- How to pass a nested function to an HTML button and Dropdown menu
- Making chartjs scrollable on the x-axis
- How to adding data in loop and display chart dynamically like in live (chart.js & typescript & angular)?
- Stacked Bar Chart, Two on Same Line w/ Same Color
- ChartJS does not render correctly
- Change background point color at runtime for angular ng2-charts / chartjs
- Chartjs does not show on pdf in yii2 despite showing in html view
- How to convert an array of strings to float in Javascript
- React chartjs 2 - Type 'string' is not assignable to type '"timeseries"'
- ChartJS tooltip label for pie cart being cut
- keep 2 chart.js contained in a div
- Loading multiple doughnut chart from chart.JS in a single component of angular 6
- Chartjs plugin label in Angular app moving unexpectedly at hover
- TemplateSyntaxError: tag name expected
- Angular ng2-charts chartsjs-plugin-labels options not working
- How do I open a dialog on clicking a Bar in the BarChart?
- trying to get minIndex and maxIndex from x-axis-0
- Chart js: bar width
- Getting Error regarding :Cannot read property 'length' of undefined
- How to display only one label in a multi line char?
- Is it possible in chartjs to hide certain dataset legends?
- Chartjs - How to update the data from values in my database?
- (Chart.js 3.7.0) change position of x-axis ticks to alternate between each tick?
- How to Change the Y axis of an Primefaces 7.0 ChartJS Linechart with Java?
- How to display data labels outside in pie chart with lines in ionic
- How to correctly transform data for a stack chart chartJS (data transformation)?