如何使用Chart.js在php中使用mysql数据绘制饼图作为饼图数据 [英] How to draw pie chart in php with mysql data as pie data using Chart.js

查看:127
本文介绍了如何使用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/[^]


这篇关于如何使用Chart.js在php中使用mysql数据绘制饼图作为饼图数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆