javascript – 如何使用JustGage按扇区显示颜色

前端之家收集整理的这篇文章主要介绍了javascript – 如何使用JustGage按扇区显示颜色前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图让我的仪表按扇区显示颜色(即在var g1上我想要绿色0-10,橙色11-22和红色23-34).

有一个选项可以做到这一点,但没有明确的指示像我这样的新手.

任何帮助,将不胜感激.

http://www.justgage.com

<script>
  var g1 = new JustGage({
    id: "score",value: <?PHP
print $content['field_anger_score'][0]['#markup'];
?>,min: 0,max: 34,title: "Your Anger score",levelColorsGradient: false
  }); 
 var g2 = new JustGage({
    id: "passive-aggressive",value: <?PHP
print $content['field_passive_aggressive_score'][0]['#markup'];
?>,max: 14,title: "Passive Aggressive"
  }); 
var g3 = new JustGage({
    id: "aggressive",value: <?PHP
print $content['field_aggressive_score'][0]['#markup'];
?>,max: 6,title: "Aggressive"
  }); 
var g4 = new JustGage({
    id: "assertive",value: <?PHP
print $content['field_assertive_score'][0]['#markup'];
?>,max: 4,title: "Assertive"
  });

</script>

DFG

解决方法

当你设置第一个量具(g1)时,我发现你正在使用levelColorsGradient:false.这应该根据文档来做.

文件

choose sector-based color representation of the displayed value. It
means color will stay green for all values below 33%,yellow from 34%
up until 66%. Take it over 67% and your gauge will glow red. These
three are the default colors.

如果你想定义自己的颜色,文件

// levelColors : string[]

// colors of indicator,from lower to upper,in RGB format

因此,创建自己的颜色变量,将下面的RGB值更改为您想要的颜色.

var myColors = [
  "#a9d70b","#f9c802","#ff0000"
]

然后在设置仪表时设置此选项.

levelColors : myColors

或者如果你想将它们保存在一起,跳过变量并执行此操作.我将中间值更改为橙色.

levelColors : [  "#a9d70b","#F27C07","#ff0000" ]

仪表现在是否显示默认颜色?我不认为你可以改变行业,它们是基于百分比.

原文链接:https://www.f2er.com/js/159155.html

猜你在找的JavaScript相关文章