Javascript 使用数据库数据将饼图保存为图像
尝试将图表另存为图像时需要一些帮助。抱歉,刚刚启动了这个新的chart.js 问题:Javascript 使用数据库数据将饼图保存为图像,javascript,php,laravel,charts,Javascript,Php,Laravel,Charts,尝试将图表另存为图像时需要一些帮助。抱歉,刚刚启动了这个新的chart.js 问题: 如何在图表中添加数据库数据?我一直试图添加$user,但它一直给我未定义的用户 这是我想从数据库中添加的数据 $users = DB::table('personal_infos') ->join('evaluations','evaluations.user_id', '=', 'personal_infos.id') ->select('evaluations.re
$users = DB::table('personal_infos')
->join('evaluations','evaluations.user_id', '=', 'personal_infos.id')
->select('evaluations.recommendation','evaluations.created_at' )
->where('evaluations.recommendation', '=', 'Yes')
->get();
现在,我只是用这样的方法来生成饼图:
<script type="text/javascript">
$("#save-btn").click(function() {
$("#canvas").get(0).toBlob(function(blob) {
saveAs(blob, "chart_1.png");
});
});
var data = [
{
value: 300,
color:"#F7464A",
highlight: "#FF5A5E",
label: "Red"
},
{
value: 50,
color: "#46BFBD",
highlight: "#5AD3D1",
label: "Green"
},
{
value: 100,
color: "#FDB45C",
highlight: "#FFC870",
label: "Yellow"
}
];
var ctx = $("#canvas").get(0).getContext("2d");
var mychart = new Chart(ctx).Pie(data,
{
//Boolean - Whether we should show a stroke on each segment
segmentShowStroke : false,
//String - The colour of each segment stroke
segmentStrokeColor : "#fff",
//Number - The width of each segment stroke
segmentStrokeWidth : 2,
//Number - The percentage of the chart that we cut out of the middle
percentageInnerCutout : 0, // This is 0 for Pie charts
//Number - Amount of animation steps
animationSteps : 10,
//String - Animation easing effect
animationEasing : "linear",
//Boolean - Whether we animate the rotation of the Doughnut
animateRotate : true,
//Boolean - Whether we animate scaling the Doughnut from the centre
animateScale : false,
//String - A legend template
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<segments.length; i++){%><li><span style=\"background-color:<%=segments[i].fillColor%>\"></span><%if(segments[i].label){%><%=segments[i].label%><%}%></li><%}%></ul>"
}
);
</script>
$(“#保存btn”)。单击(函数(){
$(“#canvas”).get(0).toBlob(函数(blob){
saveAs(blob,“chart_1.png”);
});
});
风险值数据=[
{
价值:300,
颜色:#F7464A“,
亮点:“FF5A5E”,
标签:“红色”
},
{
价值:50,
颜色:“46BFBD”,
亮点:“5AD3D1”,
标签:“绿色”
},
{
数值:100,
颜色:“FDB45C”,
亮点:“FFC870”,
标签:“黄色”
}
];
var ctx=$(“#canvas”).get(0.getContext(“2d”);
var mychart=新图表(ctx).Pie(数据、,
{
//布尔-我们是否应该在每个线段上显示笔划
错误:错误,
//字符串-每段笔划的颜色
segmentStrokeColor:#fff“,
//数字-每个线段笔划的宽度
分段行程宽度:2,
//数字-我们从中间剪下的图表百分比
percentageInnerCutout:0,//对于饼图,这是0
//Number-动画步数
动画步骤:10,
//字符串动画效果
动画化:“线性”,
//布尔-是否设置圆环旋转的动画
动画片:对,
//布尔值-是否设置从中心缩放圆环的动画
动画缩放:错误,
//字符串-图例模板
legendTemplate:“
”
}
);
尝试使用此选项