提问人:Alex 提问时间:11/16/2023 最后编辑:Professor AbronsiusAlex 更新时间:11/19/2023 访问量:29
根据动态数据值选择切片颜色
Select slice color based on dynamic data value
问:
我正在使用谷歌图表并用动态 php 数据填充图表。我有 4 家公司,想为每个公司设置切片颜色,但目前如果第 3 家公司的值为 null,那么它会显示另外 3 家公司,堆栈中有前三种颜色。现在第 3 公司的颜色适用于第 4 个公司,因为总切片是 3。我想为每个公司名称设置颜色。有什么办法吗?
var data_pie = google.visualization.arrayToDataTable([
['Value', 'Total value'],
<?php
foreach( $valueas $list_item ){
echo '["'.strtoupper( $list_item->company_name ).'", '.$list_item2->total_value.'],';
}
?>
]);
var chartheight2 = $('#piechart_3d').height();
var options_pie = {
title: 'Total Value',
titleTextStyle: {
fontSize: 16,
color:'rgb(117, 117, 117)',
bold: 0,
fontName: 'Roboto'
},
is3D: true,
'height':chartheight2,
pieSliceText: 'value',
colors: [
'#351c15',
'#462895',
'#d81013',
'#f89729'
],
legend: {position: 'bottom'},
};
var pie_chart = new google.visualization.PieChart(document.getElementById('piechart_3d'));
pie_chart.draw( data_pie, options_pie );
答: 暂无答案
评论
json_encode()
方法来构建字符串化数组,而不是在循环中将您自己的字符串组合在一起。将其输出到 JS 数组文字中将绝对正常工作。null