diff --git a/src/html/js/entries.js b/src/html/js/entries.js
index 80ad525..935cd69 100644
--- a/src/html/js/entries.js
+++ b/src/html/js/entries.js
@@ -41,6 +41,7 @@ var ListViewModel = function() {
self.selectedItem = ko.observable();
self.savedItem = ko.observable();
self.itemToRemove = ko.observable();
+ self.chart = null;
self.entriesChart = ko.computed(function() {
var entries = self.entries().slice().reverse();
@@ -355,18 +356,7 @@ ko.bindingHandlers.dateValue = {
}
};
-ko.bindingHandlers.chart = {
- init: function (element, valueAccessor, allBindingsAccessor, viewModel) {
- // empty - left as placeholder if needed later
- },
-
- update: function (element, valueAccessor, allBindingsAccessor, viewModel) {
- var unwrap = ko.utils.unwrapObservable;
- var dataSource = valueAccessor();
-
- //var entries = dataSource ? unwrap(dataSource) : null;
- var entries = dataSource ? unwrap(dataSource) : null;
-
+drawChart = function(entries, element) {
if(entries && entries.length > 0) {
var firstDate, lastDate;
var chartValues = [[], []];
@@ -388,7 +378,7 @@ ko.bindingHandlers.chart = {
$(element).html("");
// plot chart
- $.jqplot(element.id, chartValues, {
+ jqplot = $.jqplot(element.id, chartValues, {
axes:{
xaxis:{
renderer:$.jqplot.DateAxisRenderer,
@@ -419,12 +409,33 @@ ko.bindingHandlers.chart = {
//candleStick: true
}}],
});//*/
+
+ $(window).resize(function() {
+ jqplot.replot({resetAxes: true});
+ });
}
+};
+
+ko.bindingHandlers.chart = {
+ init: function (element, valueAccessor, allBindingsAccessor, viewModel) {
+ // empty - left as placeholder if needed later
+ },
+
+ update: function (element, valueAccessor, allBindingsAccessor, viewModel) {
+ var unwrap = ko.utils.unwrapObservable;
+ var dataSource = valueAccessor();
+
+ //var entries = dataSource ? unwrap(dataSource) : null;
+ var entries = dataSource ? unwrap(dataSource) : null;
+ drawChart(entries, element);
}
};
-var viewModel = new ListViewModel();
+$(document).ajaxError(function(event, xhr, settings) {
+ message("error", "Error.", xhr.statusText);
+});
+var viewModel = new ListViewModel();
ko.applyBindings(viewModel);
$(viewModel.loadAccounts);