gpt4 book ai didi

php - 选择计数字符串,然后将它们分组为饼图

转载 作者:行者123 更新时间:2023-11-29 09:59:59 25 4
gpt4 key购买 nike

我真的需要完成这个,我需要将它们按四个分组,我目前在我的表格中使用饼图来显示每个项目的百分比,以及使用此查询的计数:

This is my full code: https://www.pastiebin.com/5be43c1f6ec73

$query = "SELECT DISTINCT trendx, COUNT(*) as counter FROM jeremy_table_trend GROUP BY trendx";

这就是我查询的结果

Escalate                        99
Not Supported 12809
PE.Win32.TRX.XXPE50FFF026 23
PE.Win32.TRX.XXPE50FFF027 102
PUA.Win32.TRX.XXPE50FFF026 1
PUA.Win32.TRX.XXPE50FFF027 16
PUA.Win32.TRX.XXPE50FFF027P0005 1
Ransom.Win32.TRX.XXPE50FFF026 96
Ransom.Win32.TRX.XXPE50FFF027 619
Rapid Proliferation 596
TROJ.Win32.TRX.XX.PE50FFF026 5
Undet 1425
Undet - component 17
Undet - Feedback 712
Undet - FileSize 9
Undet - M/P 73
Undet - Maturity 146

这是我的饼图的输出,但我希望它们按 4 分组 - 未检测到、支持、升级和不支持。我怎样才能做到这一点?请帮助我

enter image description here

这是我的图表代码:

<!-- Chart code -->
<script>
var chart = AmCharts.makeChart("chartdiv", {
"fontSize":15,
"type": "pie",
"startDuration": 0,
"theme": "black",
"addClassNames": true,
"legend":{
"fontSize":15,
"position":"right",
"marginRight":250,
"autoMargins":false
},
"innerRadius": "0",
"defs": {
"filter": [{
"id": "shadow",
"width": "200%",
"height": "200%",
"feOffset": {
"result": "offOut",
"in": "SourceAlpha",
"dx": 0,
"dy": 0
},
"feGaussianBlur": {
"result": "blurOut",
"in": "offOut",
"stdDeviation": 5
},
"feBlend": {
"in": "SourceGraphic",
"in2": "blurOut",
"mode": "normal"
}
}]
},
"dataProvider":
[
<?php while($row = mysqli_fetch_array($result)): ?>

{
"TRENDX": "<?php echo $row['trendx'] ?>",
"Values": <?php echo $row['counter']; ?>
},

<?php endwhile; ?>
]
,
"valueField": "Values",
"titleField": "TRENDX",
"outlineAlpha": 0.4,
"depth3D": 30,
"balloonText": "[[title]]<br><span style='font-size:20px'><b>[[value]]</b> ([[percents]]%)</span>",
"angle": 20,
"export": {
"enabled": true
}
});

chart.addListener("init", handleInit);

chart.addListener("rollOverSlice", function(e) {
handleRollOver(e);
});

function handleInit(){
chart.legend.addListener("rollOverItem", handleRollOver);
}

function handleRollOver(e){
var wedge = e.dataItem.wedge.node;
wedge.parentNode.appendChild(wedge);
}
</script>

我正在考虑这个想法,但我不知道如何将它们按四分组

对于取消检测:

select trendx, COUNT(*) as counter from jeremy_table_trend WHERE trendx LIKE '%Undet%';

升级:

select trendx, COUNT(*) as counter from jeremy_table_trend WHERE trendx LIKE '%Escalate%';

对于不支持:

select trendx, COUNT(*) as counter from jeremy_table_trend WHERE trendx LIKE '%Not Supported%';

对于支持:

select trendx, COUNT(*) as counter from jeremy_table_trend WHERE trendx NOT LIKE '%Not Supported%' OR '%Undet%' OR '%Escalate%';

最佳答案

有几种方法可以解决这个问题,您可以使用联合查询

select 'Undet' as trendx, COUNT(*) as counter from jeremy_table_trend WHERE trendx LIKE '%Undet%'
union all
select 'Escalate', COUNT(*) as counter from jeremy_table_trend WHERE trendx LIKE '%Escalate%'
union all
select 'Not Supported', COUNT(*) as counter from jeremy_table_trend WHERE trendx LIKE '%Not Supported%'
union all
select 'Supported', COUNT(*) as counter from jeremy_table_trend WHERE trendx NOT LIKE '%Not Supported%' OR '%Undet%' OR '%Escalate%';

或者您可以使用 case 语句和子查询,例如

select status, count(*) from ( 
select
case
when trendx like '%Undet%' then 'Undet'
when trendx like '%Escalate%' then 'Escalate'
when trendx LIKE '%Not Supported%' then 'Not Supported'
else 'Supported'
end as status
) x group by status

关于php - 选择计数字符串,然后将它们分组为饼图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53208816/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com