Label Indefinite Graphic with Flot and PHP

Asked

Viewed 39 times

0

Using Flot to generate the graphics in pie format, the graph is generated with the values in percentage, 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

Filing cabinet data php. (the'accum_type' column has value)

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

print json_encode($dataset1);

1 answer

0

In his SELECT there is no column called tipo_conta_nome, then there really will never appear anything with that column.

Alter your SELECT to return some column with the name tipo_conta_nome or modify the $row[''] to the right column.

  • I tried with the code you sent, but, following the plugin’s standards, in their own examples are used the codes I use, the problem is that I can not locate the values of the label in text, ie, are displayed the values of the column '$Row['value_conta_type']' and displayed Undefined to each other.

  • My sql is SELECT tipo,status,valor,&#xA; SUM(valor) AS valor_conta_tipo,&#xA; caixa.tipo AS tipo_conta,&#xA; caixa.status AS status_conta&#xA;from caixa&#xA;where&#xA; caixa.status=1&#xA;GROUP BY tipo_conta

  • So your problem is there @sNniffer, you don’t have a parameter called tipo_conta_nome.

  • the tipo_conta_nome is to be the tipo_conta or another field you forgot in SELECT?

  • ô Maicon indeed, is missing the column, is that I informed an old sql, what I am using is: SELECT tipo,status,valor,&#xA; SUM(valor) AS valor_conta_tipo,&#xA; caixa.tipo AS tipo_conta,&#xA; caixa.status AS status_conta,&#xA; IF(caixa.tipo = '1', 'Receita','Despesa') AS tipo_conta_nome&#xA; from caixa&#xA; where&#xA; caixa.status=1&#xA; GROUP BY tipo_conta

  • @sNniffer puts a console.log(data) at the time you will create the $.plot and informs what is showing

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.