简体   繁体   English

jqplot从php-mysql检索结果

[英]jqplot to retrieve results from php-mysql

I am having problems plotting my pie chart using jqplot. 我在使用jqplot绘制饼图时遇到问题。

After getting my results from php i have converted it to json using json_encode. 从php获取结果后,我已使用json_encode将其转换为json。 The output is 输出是

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

Now when i try to put these results into my javascript 现在,当我试图把这些成果转化为我的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. 我尝试了两种方法,第一种将其放在隐藏字段中,第二种直接从PHP中检索。 Both of which result in Uncaught. No plot target specified 两者都导致Uncaught. No plot target specified Uncaught. No plot target specified errors in my Chrome console. Chrome控制台中Uncaught. No plot target specified错误。

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. 如Asad所述,我的愚蠢错误是未将Chart指定为元素。 So yeah if anyone else ever comes into the same problem, be sure to check that out. 因此,是的,如果有人遇到相同的问题,请务必检查一下。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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