0
I am trying to solve a problem with my web page. Below I put some information about it:
- The page is to generate graphs in different models (area, line, bar);
- The user, from a select chooses which type of chart he wants to create (area, line, bar);
- The data for graph generation is found in an external json file. Only each user has his or her json file with data different from each other;
- Currently, I do the Graphics with Morrisjs, but because of some limitations I’m trying to migrate to the Chartjs.
- With Morrisjs it was like this:
app.controller('GraphCtrl', function ($scope) {
$scope.changeGraph = function () {
$('#graphs').empty();
$scope.init($scope.graphType)
}
$scope.init = function (type) {
$.getJSON('/data/data4.json', function (json) {
Morris[type]({
pointSize: 2,
element: 'graphs',
data: json,
xkey: 'y',
ykeys: ['a','b','c', 'd', 'e'],
ymax: 345,
gridTextColor: ['black'],
gridTextSize: 14,
//legendTextSize: [50],
//legend: { fontSize: [30]},
//legend:{fontSize: 20},
lineColors:['red','green','purple','orange','blue'],
labels: ['CPU (% utilização)', 'Memória (% utilização)', 'Power (W)', 'CPU Temp0 (ºC)', 'CPU Temp1 (ºC)']
});
}); } });
What I’m trying to do to use the chartjs is like this:
$scope.init = function (type) {
$.getJSON('/data/data4.json', function (json) {
var ctx = document.getElementById(["graphs"]).GetContext("2d");
var graphs = new Chart(ctx)[type](data, options); }); } });
But I think there’s something wrong, because it’s not working. I’m learning now to work with web programming. If anyone can help me, I’d appreciate it
What error message you are getting from Chartjs?
– OnoSendai
None, the graph is simply not drawn and no error message appears
– DutraS
Confirming a few things then: Is the JSON file being correctly received? (You can get this information from the developer mode 'network' tab.) var
ctx
contains some value, or fails to get context? Your Chart startup (via vargraphs
) is passing 2 parameters,data
andoptions
. What are your values?– OnoSendai