3

I have the following data file:

Time;Server;Hits
2011.05.05 12:00:01;Server1;12
2011.05.05 12:00:01;Server2;10
2011.05.05 12:00:02;Server1;2
2011.05.05 12:00:02;Server2;4

So, far I have come up with the following gnuplot script:

set datafile separator ";"
set autoscale
set xdata time
set timefmt "%Y.%m.%d %H:%M:%S"
set xtics rotate 
set term png 
set output "hits.png"
set style fill solid 0.5
plot "hits.log" using 1:3 title 'Hits'

But that one plots data from both servers on the same graph as one data series. How do I make gnuplot to display 2 data series: one for each server?

0

1 Answer 1

5

I found a soluton myself:

plot "hits.log" using 1:(stringcolumn(2) eq "Server1" ? $3 : 1/0) title 'Server1' with lines,\
     "hits.log" using 1:(stringcolumn(2) eq "Server2" ? $3 : 1/0) title 'Server2' with lines
Sign up to request clarification or add additional context in comments.

4 Comments

Here's info (for others) on the "1/0" core of this solution: From the manual "The integer expression "1/0" may be used to generate an "undefined" flag, which causes a point to ignored; the ternary operator gives an example. Or you can use the pre-defined variable NaN to achieve the same result."
@nellib, do you know if it is possible to plot several series if number of series is not known beforehand? i.e. Server1 .. ServerN where is N is variable.
I don't know a nice way. You could pre-process the file to sort and space it into a data set for each server, or of course to your own solution you could add plot clauses one for each possible server (yuck!) assuming you know your max N and it's not huge. In the past for this I have written a (ruby) script to inspect the data file and generate the gnuplot plot command accordingly. There's likely a better way. You could add the "up to variable N" problem to your original question (as a bonus part) so more people see it.
@nellib, thanks for your comment. I did something similar eventually by creating a perl script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.