Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

288
Views
How to make a correct json to provide data to Apexcharts pie?

I'm new in Apexcharts, and I try to make a pie chart with data, getting from mysql database. This is the php-file named "get_types_chart.php"

$year = date('Y');
$month = date('m');

$graf = PDO()->prepare("SELECT COUNT(tickets.id) AS cid, types.ticket_type AS type_name FROM tickets LEFT JOIN types ON tickets.type=types.id WHERE tickets.arch=0 AND tickets.status NOT IN (2, 4) AND MONTH(tickets.date_create)=:month AND YEAR(tickets.date_create)=:year GROUP BY types.ticket_type");
$graf->execute([':year' => $year,
        ':month' => $month]);

$arrData = array();
while($row = $graf->fetch(PDO::FETCH_LAZY)) {
    array_push($arrData, array(
        "labels" => $row->type_name,
        "series" => $row->cid
        
    )
 );
}

$jsonEncodedData = json_encode($arrData);
header('Content-Type: application/json');
echo $jsonEncodedData;

And this is the js-code:

var url3 = 'charts/get_types_chart.php';
var options3 = {
          series: [],
          chart: {
          width: 380,
          type: 'pie',
        },
         title: {
          text: '<?php echo lang('MON_STAT_year'); ?>',
          floating: true,
          align: 'center'
        },
        labels: [],
        responsive: [{
          breakpoint: 480,
          options: {
            chart: {
              width: 200
            },
            legend: {
              position: 'bottom'
            }
          }
        }]
      };
        var chart3 = new ApexCharts(document.querySelector("#chart3"), options3);
        chart3.render();
   
        $.getJSON(url3, function(response) {
        chart3.updateSeries([{
          name: '<?php echo lang('DASH_STAT_month_all'); ?>',
          data: response
        }])
      });  

Finally I get empty pie. Please hel me to make a correct json.

about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!