javascript - 是否可以在 JustGage 图表的标题中添加图标?

标签 javascript font-awesome justgage

我正在使用 JustGage 制作图表。这是我的 JavaScript:

window.onload = function() {
  var g1 = new JustGage({
    id: "g1", 
    value: getRandomInt(0, 100), 
    min: 0,
    max: 300,
    title: "font awesome icon here"
  });
};

是否有可能获得 font awesome标题中的图标?我尝试添加 unicode (),但这不起作用。我还尝试复制并粘贴图标,结果只是生成了一个正方形。

我想要图表上方的图标,其中当前有一个正方形:

enter image description here

这是演示代码:

<!doctype html>
<html>
  <head>
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css">
    <title>Auto-adjust</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <style>
    body {
      text-align: center;
    }

    #g1, #g2, #g3 {
      width:20em; height:15em;
      display: inline-block;
      margin: 1em;
    }

    p {
      display: block;
      width: 450px;
      margin: 2em auto;
      text-align: left;
    }
    </style>

<script src="resources/js/raphael.2.1.0.min.js"></script>
<script src="resources/js/justgage.1.0.1.min.js"></script>
<script>
  var g1, g2, g3;

  window.onload = function(){
    var g1 = new JustGage({
      id: "g1", 
      value: getRandomInt(0, 100), 
      min: 0,
      max: 300,
      title: "trying to get font awesome here"
    });

    var g2 = new JustGage({
      id: "g2", 
      value: getRandomInt(0, 100), 
      min: 0,
      max: 300, 
      title: "trying to get font awesome here"
    });

    var g3 = new JustGage({
      id: "g3", 
      value: getRandomInt(0, 100), 
      min: 0,
      max: 300
      title: "trying to get font awesome here"
    });

    setInterval(function() {
      g1.refresh(getRandomInt(50, 300));
      g2.refresh(getRandomInt(50, 300));          
      g3.refresh(getRandomInt(0, 300));
    }, 2500);
  };
</script>

</head>
 <body>    
    <div id="g1"></div>
    <div id="g2"></div>
    <div id="g3"></div>
  </body>
</html>

现场演示:http://jsbin.com/layoku/1/edit?html,js,output

最佳答案

直接使用 Font awsome 作为标题的一种方法是使 Gauge 标题颜色与背景颜色相同,使其透明并将 Font 附加到 Gauge 中。需要对位置进行一些 css 样式才能将其放置在中心顶部

演示

https://jsfiddle.net/8uybzx0e/

代码

 var g1 = new JustGage({
  id: "g1", 
  value: getRandomInt(0, 100), 
  min: 0,
  max: 300,
  title: "Title",
  titleFontColor: "white"

});

$("#g1").append('<i class="fontaw fa fa-user-plus"></i>')

CSS

.fontaw {
position:absolute;
z-index:9999;
top:50px;
left:33%;
font-size:30px;
}

结果

enter image description here

关于javascript - 是否可以在 JustGage 图表的标题中添加图标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30463632/

相关文章:

javascript - 如何使用 javascript 强制 "enter key"充当 "tab key"?

css - Font Awesome 4.0 新语法

javascript - JustGage 使用 asp 网络

ruby-on-rails - 使用 gagejs 和 rails 更新 SVG

javascript - 在 NodeJS 中复制缓冲区的问题

javascript - 图片库悬停叠加高度问题

javascript - 更改div的html并在函数运行时显示它

javascript - font Awesome包中的all.js和其他JS文件的作用是什么?

javascript - 如何在我自己的脚本中包含 javascript 库

javascript - 使用 Javascript 的多个 SOAP 请求