0

I've been trying to populate my chart with data I get from an ajax request but I can not seem to figure it out. Could anyone help?

var simple_forms;
$.ajax({
    type: "GET",
    url: url,
    data: "user_id="+user_id,
    success: function(data){ simple_forms = data; },
    error: function(data) {  }
});

This is the output from the data = [1,2,3,4,5,6,7]

var weekly_line_data = {
    labels : ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
    datasets : [
    {
        label: "Simple Forms",fillColor : "transparent",strokeColor : "#53A3EB",pointColor : "#53A3EB",pointStrokeColor : "#fff",pointHighlightFill : "#2980b9",pointHighlightStroke : "#2980b9",
        data : simple_forms
    }]
}

var ctx = document.getElementById("weekly_line_data").getContext("2d");
window.myLine = new Chart(ctx).Line(weekly_line_data, {responsive: true,scaleShowGridLines : true,scaleGridLineWidth : 1,datasetStrokeWidth : 1,pointDotRadius : 5});
bryan
  • 8,879
  • 18
  • 83
  • 166
  • 2
    Are you waiting for the AJAX call to finish before your are trying to draw your chart? – m90 Aug 17 '14 at 16:34
  • It appears I was not. Thank you @m90 – bryan Aug 17 '14 at 16:48
  • @m90 if I have something like `[["1","0","0","0","0","0","0"],["0","0","0","0","0","0","0"]]`, how would I get the first section of this in js? I'd appreciate it – bryan Aug 17 '14 at 17:39
  • Use `data[0]`: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array – m90 Aug 17 '14 at 18:01
  • Had to make sure to have `dataType: 'json'` – bryan Aug 17 '14 at 18:48

0 Answers0