0👍
What you should do is create a custom binding handler for ChartJS:
ko.bindingHandlers.chartJS = {
update: function (element, valueAccessor) {
// do the chartJS stuff here
// access the chart data by calling valueAccessor()
}
};
Then you would call it in your template like so:
<canvas data-bind="chartJS: myChartData"></canvas>
Where myChartData
would be an (observable) property on your viewmodel. Should the data change (through an AJAX call), your chart will update automatically.
- Chartjs-How to display specific time label in x-axis by Chart.js?
- Chartjs-Chartjs removing labels and begin number
Source:stackexchange.com