Label Indefinida Graphic with Flot and PHP

0

Using Flot to generate pie charts, the graph is generated with the values in percent, but the labels are displayed with 'undefined'.

$(document).ready(function () {
    var chartError = function(req, status, err) {
        console.log('An error occurred: ', status, err);
    };

    function chartDataReceived(data) {
        $.plot($("#placeholder"), data, {
            series: {
                pie: {
                    show: true,
                    radius: 1,
                    label: {
                        show: true,
                        radius: 1,
                        formatter: function(label, series) {
                            return '<div style="font-size:11px; text-align:center; padding:2px; color:white;">'+label+'<br/>'+Math.round(series.percent)+'%</div>';
                        },
                        background: {
                            opacity: 0.8,
                            color: '#444'
                        }
                    }
                }


            }
        });
    }

    $.ajax({
        url: 'data.php',
        method: 'GET',
        dataType: 'json',
        success: chartDataReceived,
        error: chartError
    });
});

My select

SELECT tipo,status,valor, SUM(valor) AS valor_conta_tipo, caixa.tipo AS tipo_conta, caixa.status AS status_conta from caixa where caixa.status=1 GROUP BY tipo_conta

data.php file (the column 'type_name_name' has value)

while ($row = mysql_fetch_assoc($result))
{
    $dataset1[] = array($row['tipo_conta_nome'],$row['valor_conta_tipo']);
}

print json_encode($dataset1);
    
asked by anonymous 12.06.2015 / 02:40

1 answer

0

In your SELECT there is no column named tipo_conta_nome , so nothing will really ever appear with this column.

Change your SELECT to return some column named tipo_conta_nome or modify $row[''] to the correct column.

    
12.06.2015 / 03:03