3
works as follows, has a . js that have the graphics assembled, but with the values inserted directly, I’m having a hard time finding content that fits directly into this example that I’m using, I need a following, be it for $.ajax, getJson, whatever, pass the values of a JSON into the date field:[ 50,100,50];
A part of the code where the graph forms:
var widgetTechnologiesChart = function() {
$.getJSON("./func/dash/grafico-dash.php", "valor1", function( data ) {
console.log(data);
});
if ($('#kt_widget_technologies_chart').length == 0) {
return;
}
var randomScalingFactor = function() {
return Math.round(Math.random() * 100);
};
var config = {
type: 'doughnut',
data: {
datasets: [{
data: [
50,100,50
],
backgroundColor: [
KTApp.getBaseColor('shape', 3),
KTApp.getBaseColor('shape', 4),
KTApp.getStateColor('brand')
]
}],
labels: [
'OHSENHOR',
'OWDEUS',
'MEAJUDAAA'
]
},
options: {
cutoutPercentage: 75,
responsive: true,
maintainAspectRatio: false,
legend: {
display: false,
position: 'top',
},
title: {
display: false,
text: 'OHGLORIA'
},
animation: {
animateScale: true,
animateRotate: true
},
tooltips: {
enabled: true,
intersect: false,
mode: 'nearest',
bodySpacing: 5,
yPadding: 10,
xPadding: 10,
caretPadding: 0,
displayColors: false,
backgroundColor: KTApp.getStateColor('brand'),
titleFontColor: '#ffffff',
cornerRadius: 4,
footerSpacing: 0,
titleSpacing: 0
}
}
};
var ctx = document.getElementById('kt_widget_technologies_chart').getContext('2d');
var myDoughnut = new Chart(ctx, config);
}
And so, I did a lot of research before I got here, but I didn’t find anything that could add me up, and the funny thing is that this code that I posted, if I play it complete even within the proper tag in php it doesn’t render the graph, being that it’s based on Chartjs, Does anyone know how I handle this situation? I tried to use $.getJSON, but it didn’t work, so I just left it in the code as an example of the last thing I tried to use.
The return of json:
{ "Valor1": 50 }{ "Valor2": 80 }
Lauro, thank you very much for the help, I understood about the functions above, I tried to use the date: [50, 100, 50, ...jsondata] but when it comes to loading the chart it does not carry the value returned by json, I need that instead of leaving the predefined values, it only pulls the values that json returns: Example: JSON { "valor1": "7039" }{ "valor2": "8150" } Would it be in some of the above forms? or otherwise? Excuse my ignorance :/
– Antonio Dvino
Yes, in this case you must iterate and add the matrix the value of each object you want
– Lauro Moraes
Is there a way you can show me a practical example in code? I am very raw in js :/
– Antonio Dvino
Edit your question by adding a minimal example of what comes back from this json and what you want to use from it. I edit my reply with an iteration example using this return
– Lauro Moraes
Okay, I put what my json returns.
– Antonio Dvino
@Antoniodvino, edited response. Give feedback when possible
– Lauro Moraes
Lauro, without words, you helped me very, very much, I am immensely grateful that you helped me! I’ve been hitting my head with this for days, intendendo now in practice how it works, I think I’ll be able to solve some impasses, thank you very much man! You are a beast, you should teach face because you explained detail by detail, I was very lay that I caught, but you helped me a lot! Thanks! <3
– Antonio Dvino