我已经在bash / html中开发了一个CGI,可以用来生成集群图。
这是一个效果很好的图表。问题在于,对于某些图形,百分比重叠或偏离应有的位置太远。这是我的GNUPLOT代码:
f(w) = (strlen(w) > 10 ? word(w, 1) . "\n" . word(w, 2) : w)
set title "TITLE"
set terminal png truecolor size 960, 720 background rgb "#eff1f0"
set output "/var/www/html/CLUSTER_NAME.png"
set bmargin at screen 0.1
set key top center
set grid
set style data histograms
set style fill solid 1.00 border -1
set boxwidth 0.7 relative
set yrange [*:*]
set format y "%g%%"
set datafile separator ","
plot 'test1.txt' using 2:xtic(f(stringcolumn(1))) title " CPU consumption (%) ", \
'' using 3 title " RAM consumption (%)", \
'' using 0:($2+1):(sprintf(" %g%%",$2)) with labels notitle, \
'' using 0:($3+1):(sprintf(" %g%%",$3)) with labels notitle
这是一个图表示例,该图表由于百分比偏移过大而无法正常工作:
我可以通过更改代码中的这一行来更改它:
'' using 0:($3+1):(sprintf(" %g%%",$3)) with labels notitle
收件人:
'' using 0:($3+1):(sprintf(" %g%%",$3)) with labels notitle
添加空格可以更改百分比:
但是即使适用于该图,它也会移动其他图的百分比...:
我无法获得“干净”的图形。要么百分比重叠,要么因为值太大而超出范围,或者它们完全偏移。...
是否有一种方法可以自动根据值以及条形等的大小自动移动所有内容?
答案 0 :(得分:0)
您可以尝试使用另一种机制,即使用plot for [i=2:3] ...
遍历两列值。不用猜测要缩进的空格数,而是使用column(0)+(i-2)*.25
(对于i = 2然后是3)来估计条的x位置,
这是我反复尝试得出的。
例如,使用函数mytitle
获取2个标题(我的gnuplot对于数组而言太旧了):
mytitle(x) = (x==2?"cpu":"ram")
plot for [i=2:3] 'data' using i:xtic(stringcolumn(1)) title mytitle(i), \
for [i=2:3] '' using (column(0)+(i-2)*.25):(column(i)+1):\
(sprintf("%g%%",column(i))) with labels notitle