score:1
Accepted answer
you can put the code that draws the chart in a function and call that function on both the $(document).ready
and $("#submit-btn").click
event, like this:
function drawchart() {
var outputyearly = $('#outputyearly');
var amount = parseint($('#amount').val().replace(/,/g, ''), 10);
var rate = parsefloat($('#rate').val(), 10);
var term = parsefloat($('#term').val(), 10);
//destroy the dougnut chart here, not sure how it's accessible, but it won't work through window.onload
var ctx = document.getelementbyid("mychart").getcontext("2d");
new chart(ctx, {
type: 'doughnut',
data: data,
options: options
});
}
$(document).ready(function() {
drawchart();
$("#submit-btn").click(function (e) {
e.preventdefault();
drawchart();
});
});
note that $(document).ready
already imposes the code inside of it to be executed when the page is done, so putting a window.onload
inside of it won't make any difference.
Source: stackoverflow.com
Related Query
- Loading or Activating ChartJS on Load
- Loading an external JSON into ChartJs
- How to add ChartJS code in Html2Pdf to view image
- Loading json file to chartjs
- How do I add time sourced from an external source as an X axis to a ChartJS graph?
- How can I load multiple Chartjs charts with different data on the same page?
- Load ChartJS via VueJS - ChartJS empty and 0px dimension
- Chartjs not working with d3 from csv source
- load external json data file in to chartjs in the angular component
- When I added a funnel chart to chartjs all the charts are load compressed until resize page
- ChartJS have xAxes labels match data source
- ReactJS - Loading data using Axios + chartjs
- Updating Chartjs to 2.5 with custom code
- ChartJs 2 How to remove numbers from the doughnut chart on loading
- ChartJS AJAX load labels and data
- Calling data from outside of Chartjs code
- VueJS + Chartjs - Chart only renders after code change
- Angular 2+: How to load a data to chartjs graph in every second in Angular
- ChartJS 2.0 differences in code help needed
- Angularjs lazy load chartjs when in another tab
- My Chartjs is not updating after setstate full code attached Reactjs Update
- Chartjs doc examples are lightning fast but same code is slow when reproducing
- chartjs loading data from ajax doesn't work fine
- 'require is not defined' error when attempting to use chartjs in javascript code
- how to load mysql query to chartjs with php?
- Load data into chartjs using promises in vue.js
- How to run Chart.js samples using source code
- Code for Chartjs Typescript definition file
- Dynamically update values of a chartjs chart
- Different color for each bar in a bar chart; ChartJS
More Query from same tag
- Only first value added gets displayed in ng2-chart linechart
- My ChartJS Line needs to click the color legend first before it plots the data
- How to convert an array of strings to float in Javascript
- Chart js options not changing chart
- Updating chart.js chart with dataset of different size
- Add options to Charts.js
- cartjs tooltips displays in the wrong place on a chart
- ChartJS 3 doesn't display legend
- Customise size of data points , height and width in Chart.js?
- [Vue warn]: Error in mounted hook: "TypeError: this.$refs.canvas is undefined"
- Need help adding Chart.js chart to a Modal window (I'm Using AngularJS)
- How to add image inside the doughnut chart using chart.js?
- react-chartjs: difference between `scales.x`/`xAxes`/`xAxes[]`
- angular 5 chart.js Failed to create chart
- Hide points in ChartJS LineGraph
- Ionic 3 + Angular 4 + chart.js - loading data from array
- Chart.js v2 hide dataset labels
- Is there anyway to remove the dots for points from angularjs charts
- Can I arrange labels of legend in Doughnut chart one by one?
- How to remove only one specific dataset label chartJS?
- Angular 8 & ChartJs change color in pie chart
- Extend chart.js horizontal bar graph to include a vertical line
- UndescoreJS - Convert Object Properties Into Arrays
- How to update chart at the end of every for loop in Chart.js?
- Chartjs: How can I group datasets closer if I have maxBarThickness set?
- MongoDB based data is not populating in Chart.js
- How to incorporate chart.js in jsp file
- Cycle through finite set of colours for indefinite set of data in Javascript
- react-chart-js-2 keep bar width no matter what the number of bar is
- chart.js radar scaleShowLine for each scaleLine