I have a ajax call to the database to get date fields, which are basically like this.["2016-3", "2016-5", "2016-6", "2016-7", "2016-8"]
, When I call them from the db I get them exactly as the way you see in the array, but I cannot get them working on the chart, if I manually type those array it works but if I use an observableArray or just a ordinary js array both do not work. Here is the code for the ajax call being made.
var arr = [ ]; //normal js array
self.DateArray = ko.observableArray(); // knockout js array
self.LineChart = function () {
$.ajax({
type: 'POST',
url: BASEURL + 'index.php/moneyexchange/portfolioDevelopment/' + auth ,
contentType: 'application/json; charset=utf-8'
})
.done(function(data) {
console.log(data);
arr = data.slice();
self.DateArray(data);
console.log(self.DateArray());
console.log(arr);
})
.fail(function(xhr, status, error) {
alert(status);
})
.always(function(data){
});
};
self.LineChart();
Both the console.log shows this.
The line chart is working since the values are manually typed in.
this.MasnadsLineChart = {
labels: ["2016-3", "2016-5", "2016-6", "2016-7", "2016-8"],
datasets: [
{
label: "My First dataset",
fillColor: "rgba(220,220,220,0.1)",
strokeColor: "yellow",
pointColor: "#ffcc33",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(220,220,220,1)",
data: [65, 59, 80, 81, 56, 55, 40,80, 81, 56, 55, 40]
},
{
label: "My Second dataset",
fillColor: "rgba(151,187,205,0.1)",
strokeColor: "rgba(151,187,205,1)",
pointColor: "rgba(151,187,205,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(151,187,205,1)",
data: [41, 48, 40, 19, 86, 27, 90 ,80, 81, 56, 55, 40]
}
]
};
I tried writing labels : self.DateArray()
and even labels : arr
both do not work, now I am confused on how to get those values to work on the graph.
this is what the ajax call is bringing back
and here is the link from where I got the chart https://github.com/grofit/knockout.chart