简体   繁体   中英

jqplot to retrieve results from php-mysql

I am having problems plotting my pie chart using jqplot.

After getting my results from php i have converted it to json using json_encode. The output is

{"a":2,"b":1,"c":5,"d":650}

Now when i try to put these results into my javascript

<script class="code" type="text/javascript">
$(document).ready(function(){
    // method 1
    //var data1 = document.getElementById("dataArray").value;
    //eval('data1 = '+data+';');

    // method 2
    var data1 = <?php echo json_encode($data); ?>;

    var plot1 = jQuery.jqplot ('Chart', [data1], 
    { 
        seriesDefaults: {
            // Make this a pie chart.
            renderer: jQuery.jqplot.PieRenderer, 
            rendererOptions: {
                // Put data labels on the pie slices.
                // By default, labels show the percentage of the slice.
                showDataLabels: true
            }
        }, 
        legend: { show:true, location: 'e' }
    }
    );
});
</script>

I've tried two methods, the first to put it inside a hidden field, and the second to retrieve straight from PHP. Both of which result in Uncaught. No plot target specified Uncaught. No plot target specified errors in my Chrome console.

What is it I am doing wrong here?

Thanks guys.

As Asad mentioned, my stupid mistake was that Chart was not specified as an element. So yeah if anyone else ever comes into the same problem, be sure to check that out. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM