Chart on Custom File

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
thomas
User
Posts: 131

Chart on Custom File

Post by thomas »

In PHPMaker 2022 is there are function or option to add chart on custom file using the sql query
just like ExecuteHtml() function


arbei
User
Posts: 9284

Post by arbei »

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"); ?>,
    ...
});

ach8
User
Posts: 174

Post by ach8 »

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?



Post Reply