【发布时间】:2015-02-09 10:08:47
【问题描述】:
我有以下 csv 文件:
timestamp,unit,maximum,average
Thu Feb 05 14:54:00 GMT 2015,Percent,13.0,4.503333333333333
当我在其上运行以下 bash 脚本时:
#!/bin/bash
graph_results() {
input=cpu-samples.csv
output=cpu-samples.png
gnuplot <<- eor
set terminal png
set output '${output}'
set style data linespoints
set xdata time
set timefmt '%b %d %H:%M:%S GMT %Y'
set format x '%b %d %Y %H:%M'
set datafile separator ","
set xlabel "timestamp"
set ylabel "percent"
set xtics rotate
plot '< tail -n +2 ${input} | cut -f 1 --complement -d" "' using 1:3 title 'Maximum', '' using 1:4 title 'Average'
eor
}
graph_results
我收到以下错误:
bash-4.1$ ./run_gnuplot
Could not find/open font when opening font "arial", using internal non-scalable font
Warning: empty x range [4.76463e+08:4.76463e+08], adjusting to [4.71699e+08:4.81228e+08]
生成的图表上有正确的数据点和时间戳,但图表中的 x 轴日期值不正确。
当 csv 文件中包含多个值时它可以正常工作,但当只有一个值时则不行。我意识到错误消息是因为使用一个值,x 轴的开始和结束范围是相同的(如此处所述http://gnuplot.10905.n7.nabble.com/empty-x-range-td1650.html)。
我知道我可以设置以下范围:
set xrange
但由于我使用的是自定义日期格式,而且我不知道开始日期和结束日期应该是什么,因为生成的数据是动态的,因此不确定我该如何使用?
【问题讨论】: