XQuery/Google 圖表子彈條
外觀
< XQuery
要顯示一個 子彈圖表 來顯示系統引數的當前值及其安全和危險範圍。
這是現在已棄用的 " Google 圖表 API 支援的圖表型別之一,該 API 從 URL 引數構建圖表。
http://chart.apis.google.com/chart?cht=bhs&chs=150x30&chd=t:70&chm=r,ff0000,0,0.0,0.5%7Cr,ffff00,0,0.5,0.75%7Cr,00A000,0,0.75,1.0%7Cr,000000,0,0.8,0.81&chco=000000&chbh=10

圖表設計的 XML 表示可能是
<chart >
<type>bar-gauge</type>
<height>30</height> <!-- in pixels -->
<width>150</width> <!-- in pixels -->
<danger-threshold>50</danger-threshold> <!-- end of danger level -->
<danger-color>ff0000</danger-color>
<warning-threshold>75</warning-threshold> <!-- end of warning level -->
<warning-color>ffff00</warning-color>
<ok-threshold>100</ok-threshold> <!-- end of ok level -->
<ok-color>00ff00</ok-color>
<target-value>90</target-value>
</chart>
當與當前值一起提供時,必須將其轉換為以下 URL
http://chart.apis.google.com/chart?
cht=bhs&
chs=150x30&
chd=t:70&
chm=r,ff0000,0,0.0,0.5|
r,ffff00,0,0.5,0.75|
r,00A000,0,0.75,1.0|
r,000000,0,0.8,0.81&
chco=000000&chbh=10
此函式接受圖表規範和當前值,並生成相應的 Google 圖表 URL。
請注意,危險、警告和良好條(紅色、黃色和綠色)的寬度以百分比表示,從 0 到 100。
declare function local:bullet-bar($spec,$current-value) {
let $danger-width-percent := $spec/danger-threshold div 100
let $warn-width-percent := $spec/warning-threshold div 100
let $ok-width-percent := $spec/ok-threshold div 100
let $target-width-percent := $spec/target-value div 100
let $target-plus-one := $target-width-percent + 0.01
return concat(
'http://chart.apis.google.com/chart?cht=bhs&chs=',
$spec/width,
'x',
$spec/height,
'&chd=t:',$current-value,
'&chm=r,',$spec/danger-color,',0,0.0,', $danger-width-percent,
'|r,',$spec/warning-color,',0,', $danger-width-percent, ',', $warn-width-percent,
'|r,',$spec/ok-color,',0,', $warn-width-percent, ',', $ok-width-percent,
'|r,000000,0,', $target-width-percent, ',', $target-plus-one,
'&chco=000000&chbh=',
round($spec/height * 0.6)
)
};
let $current-value := 70
let $url := local:bullet-bar($bar-spec,$current-value)
return
<div>
<h2>Example bullet bar</h2>
<div> <img src="{$url}"/></div>
</div>