1

我在 spotfire 文本区域中有一个小的 javascript。它按设计工作。我保存并关闭了spotfire。重新打开时根本不显示。我的代码如下。任何帮助,将不胜感激。

resource = [
  "//cdn.rawgit.com/toorshia/justgage/master/raphael-2.1.4.min.js",
  "//cdnjs.cloudflare.com/ajax/libs/justgage/1.2.8/justgage.js"
]

//add scripts to head
$.getScript(resource[0], function() {
  $.getScript(resource[1], init)
})

var init = function() {
  var g = new JustGage({
    id: "gauge",
    min: 0,
    max: 100,
    customSectors: [{
        "lo": 0,
        "hi": 89.999,
        "color": "#f05050"
      },
      {
        "lo": 90,
        "hi": 92.999,
        "color": "#DD7502"
      },
      {
        "lo": 93,
        "hi": 100,
        "color": "#41c572"
      }
    ],
    levelColorsGradient: false
  });
  //refresh gauge when calcvalue changes
  $(calcValue).on('DOMSubtreeModified', function() {
    g.refresh($(this).text())
  })
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span id=calcValue><SpotfireControl id="3321e4c9003142ad83fdb753e6f66605" />
</span>
<DIV id=gauge></DIV>

4

2 回答 2

0

我看了例子,应该是:

resource = [
  "//cdn.rawgit.com/toorshia/justgage/master/raphael-2.1.4.min.js",
  "//cdnjs.cloudflare.com/ajax/libs/justgage/1.2.8/justgage.js"
]

//add scripts to head
$.getScript(resource[0], function() {
  $.getScript(resource[1], init)
})

var init = function() {
  var g = new JustGage({
    id: "gauge",
    min: 0,
    max: 100,
    customSectors: {ranges: [{
        "lo": 0,
        "hi": 89.999,
        "color": "#f05050"
      },
      {
        "lo": 90,
        "hi": 92.999,
        "color": "#DD7502"
      },
      {
        "lo": 93,
        "hi": 100,
        "color": "#41c572"
      }
    ]},
    levelColorsGradient: false
  });
  //refresh gauge when calcvalue changes
  //$(calcValue).on('DOMSubtreeModified', function() {
  //  g.refresh($(this).text())
  //})
  window.setInterval( () => {
    g.refresh(Math.random()*100)
  }, 1000)
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span id=calcValue><SpotfireControl id="3321e4c9003142ad83fdb753e6f66605" />
</span>
<DIV id=gauge></DIV>

于 2017-07-19T02:39:04.400 回答
0

我们的 JustGage 设置有点不同,但我们遇到了同样的计算问题,当仪表板在 Web 浏览器等上打开时没有显示。

问题(至少我认为)是异步代码。原代码是这样的:

    resource=[
     "//cdnjs.cloudflare.com/ajax/libs/raphael/2.1.4/raphael-min.js",
     "//cdnjs.cloudflare.com/ajax/libs/justgage/1.2.9/justgage.js"
    ]


    $.getScript(resource[0],function(){
     $.getScript(resource[1],init3)
    })


    //init3 function generates the gauge chart
    init3 =function(){
      var g3 = new JustGage({
        id: "gaugeIRF", 
        value:  $('#calcValueIRF').text(), 
        min: 0,
        max: 100,
        levelColors : [  "#73CC06", "#dec121",  "#dec121", "#bd5537" ],
        levelColorsGradient: false,
        symbol:'%',
        pointer: true,
        gaugeWidthScale: 0.6,
        counter: true,
        relativeGaugeSize: true,
        title: "IRF Readmission Rate"
      });

      //refresh gauge when calcvalue changes
      $('#calcValueIRF').on('DOMSubtreeModified',function(){
        g3.refresh($(this).text())
      })
    }

init3 函数将运行,当浏览器读取 init3 时,CalcValue 将计算,但很可能 init3 将在 CalcValue 能够返回数字之前完成运行。这是异步的,两个进程没有按正确的顺序完成。这就是为什么当浏览器打开或您返回仪表板时,计算不会显示。

解决方案是放置一个功能。函数中的函数以 JavaScript 的正确顺序运行。这是我的工作代码:

    resource=[
     "//cdnjs.cloudflare.com/ajax/libs/raphael/2.1.4/raphael-min.js",
     "//cdnjs.cloudflare.com/ajax/libs/justgage/1.2.9/justgage.js"
    ]


    $.getScript(resource[0],function(){
     $.getScript(resource[1],init3)
    })


    //new function to get the calculated value
    function getValue3(){
      var newValue = $('#calcValueIRF').text()
      return newValue
    }


    init3 =function(){
      var g3 = new JustGage({
        id: "gaugeIRF", 
        value:  getValue3(), 
        min: 0,
        max: 100,
        levelColors : [  "#73CC06", "#dec121",  "#dec121", "#bd5537" ],
        levelColorsGradient: false,
        symbol:'%',
        pointer: true,
        gaugeWidthScale: 0.6,
        counter: true,
        relativeGaugeSize: true,
        title: "IRF Readmission Rate"
      });

      //refresh gauge when calcvalue changes
      $('#calcValueIRF').on('DOMSubtreeModified',function(){
        g3.refresh($(this).text())
      })
    }
于 2018-11-28T20:00:43.400 回答