Chart on Custom File
In PHPMaker 2022 is there are function or option to add chart on custom file using the sql query
just like ExecuteHtml() function
In PHPMaker 2022 is there are function or option to add chart on custom file using the sql query
just like ExecuteHtml() function
There is not, but you may use ExecuteJson()
to get data from database for your chart, e.g.
<?= ExecuteJson("SELECT label AS x, value AS y FROM mytable"); ?>;
you'll get data in array of object, e.g.
[{"x": "label1", "y": value1}, {"x": "label2", "y": value2}, ...];
This can be set as data for Chart.js directly, see Data structures. So you may create a chart easily like:
const myChart = new Chart(document.getElementById('myChart'), {
type: 'bar',
data: <?= ExecuteJson("SELECT label AS x, value AS y FROM mytable"); ?>,
...
});
How to make table popup with click action on chart?
canvasP.onclick = function(e) {
var slice = myPieChart.getElementAtEvent(e);
if (!slice.length) return; // return if not clicked on slice
var label = slice[0]._model.label;
$('#ppejp_modal').modal('show');
$('.modal-title').html('Data');
switch (label) {
// SHOW TABLE IN HERE
// HOW TO SHOW TABLE INI POPUP DATA
$('.modal-body').html(TABLE_HERE);
}
}
How to other solution?