2
votes

Thank You very much for Read this and i apologize if my english is not very good.

Well, i'm trying to do a highchart pie chart, but the labels don't appear, only the numbers. i've been searching, but i can't find the answer, and i'm new in this.

This is my data_2.php file:

<?php 

$con = mysql_connect("localhost","root",""); 

if (!$con) {   die('Could not connect: ' . mysql_error()); } 

mysql_select_db("pymesonline", $con); 

$result = mysql_query("SELECT descripcion_p, sum(cantidad_vendida) FROM venta_producto GROUP BY descripcion_p"); 

    while($row = mysql_fetch_array($result)) {
        echo $row['descripcion_p'] . "\t" . $row['sum(cantidad_vendida)']. "\n"; } 
    mysql_close($con); 

?>

And this my script:

var a = jQuery.noConflict();
a(document).ready(function(){

var chart;
var options = {
                    chart: {
                        renderTo: 'container',
                        plotBackgroundColor: null,
                        plotBorderWidth: null,
                        plotShadow: false
                    },

                    title: {
                        text: 'Productos Mas Vendidos',
                        x: -20 //center
                    },

                    subtitle: {
                        text: 'Historico',
                        x: -20
                    },


                    series: [{
                        type: 'pie',
                        name: 'Cantidad Vendida',

                        }]

                    }

    jQuery.get('clases/data_2.php', null, function(tsv) {
                    var lines = [];
                    traffic = [];
                    try {
                        // split the data return into lines and parse them
                        tsv = tsv.split(/\n/g);
                        jQuery.each(tsv, function(i, line) {
                            line = line.split(/\t/);
                            date = Date.parse(line[0]);
                            traffic.push([
                                date,
                                parseInt(line[1].replace(',', ''), 10)
                            ]);
                        });
                    } catch (e) {  }
                    options.series[0].data = traffic;
                    chart = new Highcharts.Chart(options);
                });
});

The result is this, and i don't know what is wrong, everything it's ok, except by the labels. I appreciate too much the helps, thank you so much.

This is the Result

3

3 Answers

1
votes

Maybe you need add series of a data name:

        options.series[0].data = traffic;
        options.series[1].data = traffic1;
        chart = new Highcharts.Chart(options);

And put a series of name in a array of options:

    var options = {

    series: [{
                    name: 'Saldo'
                },{
                    name: 'Saldo1'
                }]
0
votes

Ok, i surrender with this.

i do it this way

    series: [{
        type: 'pie',
        name: 'Cantidad Vendida',
        data: [
            <?php 
                $con = mysql_connect("localhost","root",""); 
                if (!$con) {   die('Could not connect: ' . mysql_error()); } 
                    mysql_select_db("pymesonline", $con); 
                    $result = mysql_query("SELECT descripcion_p, sum(cantidad_vendida) FROM venta_producto GROUP BY descripcion_p"); 
                while($row = mysql_fetch_array($result)) {
                echo "["."'".$row['descripcion_p']."'"."," . $row['sum(cantidad_vendida)']."]".","."\n"; 
                } 
                mysql_close($con); 
                ?>
        ]
    }]

And it's working very well.

0
votes

Ignacio,

I've encountered same problem and finally get through -- you should not use jQuery.get() function to pull a JSON object, you should use jQuery.getJSON() instead.

You can google the difference between the two functions.