如何使用Chart.js在php中使用mysql数据绘制饼图作为饼图数据

问题描述:

我希望在项目中为饼图添加代码段。我搜索并找到了一些简单图表的代码。我的页面图表的部分如下:



I wish to add code snippets for pie chart in my project. I searched and found some code for simple chart.Part of my page for chart is below:

printf( '<script type="text/javascript" src="extlib/Chart.js"></script>' );
printf( '<script type="text/javascript" src="extlib/jquery-min.js"></script>' );
printf( '<canvas id="mycanvas" width="256" height="256"></canvas>' );
printf( '<script type="text/javascript">' );
 
    var ctx = $("#mycanvas").get(0).getContext("2d");
    var piedata = [
    {
    value:30,
    color:"green",
    label:"sta1",
    labelColor : 'white'
    },
    {
    value:60,
    color:"red",
    label:"sta1",
    labelColor : 'white'
    },
    {
    value:50,
    color:"blue"
    }
    ]

    new Chart(ctx).Pie(piedata);
        printf( '</script>' ); 







我可以为动态图表做些什么。这个值应该来自MySQL DB。来自DB的数据值每次都会有所不同。每个数据值都有特定的颜色。





请建议我如何使用使用mysql和Chart.js




What can I do for dynamic chart.That is the value should come from MySQL DB. Number of data value from DB will differ every time.Each data value has specific colors.


Please suggest me the way of how to do with mysql and Chart.js

#mycanvas)。get(0).getContext( 2d);
var piedata = [
{
value:30,
color: green
label: sta1
labelColor:' white'
},
{
value :60,
颜色: red
label: sta1
labelColor:' white'
},
{
value:50,
color: blue
}
]

新的图表(ctx).Pie(piedata);
printf(' < / script>');
("#mycanvas").get(0).getContext("2d"); var piedata = [ { value:30, color:"green", label:"sta1", labelColor : 'white' }, { value:60, color:"red", label:"sta1", labelColor : 'white' }, { value:50, color:"blue" } ] new Chart(ctx).Pie(piedata); printf( '</script>' );







我可以为动态图表做些什么。这个值应该来自MySQL DB。来自DB的数据值每次都会有所不同。每个数据值都有特定的颜色。





请建议我如何使用使用mysql和Chart.js




What can I do for dynamic chart.That is the value should come from MySQL DB. Number of data value from DB will differ every time.Each data value has specific colors.


Please suggest me the way of how to do with mysql and Chart.js


使用Chart.js [PHP] [ ^ ]可以帮助你。



额外资源 -

https://github.com/HugoHeneault/Chart.js-PHP [ ^ ]

http://www.sitepoint.com/fancy-responsive-charts-with-chart-js/ [ ^ ]
Using Chart.js [PHP] [^] might help you.

Additional resources -
https://github.com/HugoHeneault/Chart.js-PHP[^]
http://www.sitepoint.com/fancy-responsive-charts-with-chart-js/[^]