douyingp82418 2017-06-07 07:33
浏览 47

从最大值插入颜色

So I'm working on the cohort analysis, creating a table from the database, and having a trouble when it comes to coloring. I'm not an expert at javascript, so I dont really know how to do it.

So for example, I have 10,2,6,4.

And then in the table, I wanted to give a coloring from the biggest value.

like

10 => Darkest Green
2 => Lightest Green
6 => Dark Green
4 => Light Green

So if we sort it to make it easier,

10 => Darkest Green
6 => Dark Green
4 => Light Green
2 => Lightest Green

Edit: The 4 number above just a raw example, I'm doing a monthly cohort, which means I will have 12 number, and it will be random, and many months will also have 0, which means it will be white/super light green.

How can I do that? Thanks a lot, and sorry for my english

  • 写回答

1条回答 默认 最新

  • dongtang7347 2017-06-07 07:38
    关注

    you can create an array with high priority of colors to low. like:

    $colors = array( "Darkest Green", "Dark Green", "Light Green", "Lightest Green" );

    now you can use 'foreach' in php to assign that color. like:

    $i = 0;
    $new_result = array();
    
    foreach( $cohort_result as $row ) {
    
        $new_result[ $row ] = $colors[ $i ];
        $i++;
    
    }
    

    Regards.

    评论

报告相同问题?

悬赏问题

  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入