mdbootstrap chart with json data - how to import

web
mobile

Topic: mdbootstrap chart with json data - how to import

Klaudia asked 6 months ago

I would really appreciate if somebody could help me with figured out how to import data from external json file into the bootsrap chart.

I have already tried to write something based on the line chart but it doesn't show any data on the chart.

Here is the part of the full code:

$(document).ready(function() { var data = []; $.getJSON("https://api.myjson.com/bins/45rin", function(result) { for (var i = 0; i <= result.dataPoints.length - 1; i++) { data.push({ labels:result.dataPoints[i].label, datasets:({

    data: parseInt(result.dataPoints[i].y)
  })
})}

var ctxL = document.getElementById("BBBB").getContext('2d'); var myLineChart = new Chart(ctxL, { type: 'line', data: data

});

myLineChart.update();


Magdalena Dembna staff premium commented 6 months ago

Hi, can you create a code snippet here: https://mdbootstrap.com/snippets/? It would be much easier to reproduce your case and find a solution.


Klaudia commented 6 months ago

https://mdbootstrap.com/snippets/jquery/garncarczyk/1267102 - here is the link

id= chartContainer - it is an example which I found (It works in CHROME on my comp) id=lineChartA1 - mdbootsrap chart id=BBBB - mdbootrap chart into which I would like to upload the data from json


Magdalena Dembna staff premium commented 6 months ago

I have created a code snippet with the call to your API: https://mdbootstrap.com/snippets/jquery/m-dembna/1275976#js-tab-view


Klaudia commented 6 months ago

Thank you very much! That is exactly what I was looking for :)


Please insert min. 20 characters.
Status

Resolved

Specification of the issue
  • User: Free
  • Premium support: No
  • Technology: General Bootstrap questions
  • MDB Version: -
  • Device: DELL
  • Browser: CHROME
  • OS: Windows 7
  • Provided sample code: No
  • Provided link: Yes