Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

295
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda