print all the data of an array in a highcharts

0

Hi, I have a little problem with highcharts, so the graph shows the last area. Of the forty areas, the problem is that I can not go through the entire arrangement so that all my code is shown as follows:

 case 5:
        //lineal
        $consulta = $obj->getQueryConsulta();
        $result = $catalogo->obtenerLista($consulta);
        $datos = array();
        while ($row = mysql_fetch_array($result)) {
            $datos[$row['datos']] = $row['series'];
        }
        print_r($datos);
    $menu = count($datos);



        echo "<script>Highcharts.chart('container', {

title: {
    text: '" . $obj->getDescripcion() . "'
},

subtitle: {
    text: 'Source: thesolarfoundation.com'
},

yAxis: {
    title: {
        text: '" . $obj->getDescripcion() . "'
    }
},
legend: {
    layout: 'vertical',
    align: 'right',
    verticalAlign: 'middle'
},

plotOptions: {
    series: {
        label: {
            connectorAllowed: false
        },
        pointStart: 2010
    }
},";

        foreach ($datos as $key => $value) {

            echo "series: [{

    name: '" . $key . "',";
            echo ' data: [';

            echo"$value]

";
            echo"}";
            echo"],";

            echo" ";
        }
        echo "
responsive: {
    rules: [{
        condition: {
            maxWidth: 500
        },
        chartOptions: {
            legend: {
                layout: 'horizontal',
                align: 'center',
                verticalAlign: 'bottom'
            }
        }
    }]
}});  </script>";
        break;

The highcharts only shows the last area of the array

Array ( [Dirección] => 1 [Sistemas] => 25 [Comunicación Social] => 0   [Desarrollo Institucional] => 0 [S. Técnica] => 3 [Indicadores] => 0 [Exhibición] => 0 [Registro] => 0 [Fotografía] => 0 [Comunicación] => 1 [Difusión] => 1 [Electrónicos] => 0 [Prensa] => 0 [Mediación] => 0 [Académicos] => 0 [Editorial] => 0 [Arquitectura] => 0 [Museografía] => 0 [Administración] => 0 [Presupuesto] => 0 [R. Humanos] => 0 [R. Materiales] => 0 [R. Financieros] => 0 [Jurídico] => 0 [Custodios] => 0 [Amigos P.] => 0 [Seguridad] => 0 [Amigos D. E.] => 0 [Amigos S.] => 0 [Contabilidad P.] => 0 [Tienda] => 0 [Cultura] => 0 [INBA] => 0 [Taquilla] => 0 [Archivo] => 0 [Servicios al Público] => 0 [Servicio Social] => 0 [Diseño] => 0 [Proyectos Especiales] => 0 [Personal de Museo] => 0 ) 
    
asked by carlos becerra 31.10.2018 в 19:25
source

1 answer

0

I think you should put series outside the loop like this:

echo "series[";
foreach ($datos as $key => $value) {
        echo "{
                name: '" . $key . "',";
        echo '  data: [';
        echo   "$value]";
        echo"},";            
}
echo "],";
    
answered by 31.10.2018 в 19:29