I have recently pushed a new version to git which makes it easy to support custom datatypes such as this. To support your struct Data, you can provide a specialization of the TextSender class. Here is a complete example, using the struct you defined.
#include <vector>
#include "gnuplot-iostream.h"
struct Data {
std::string datestr; // x axis value
float f1; // y axis series 1
float f2; // y axis series 2
float f3; // y axis series 3
};
typedef std::vector<Data> Dataset;
namespace gnuplotio {
template<>
struct TextSender<Data> {
static void send(std::ostream &stream, const Data &v) {
TextSender<std::string>::send(stream, v.datestr);
stream << " ";
TextSender<float>::send(stream, v.f1);
stream << " ";
TextSender<float>::send(stream, v.f2);
stream << " ";
TextSender<float>::send(stream, v.f3);
// This works too, but the longer version above gives
// gnuplot-iostream a chance to format the numbers itself (such as
// using a platform-independent 'nan' string).
//stream << v.datestr << " " << v.f1 << " " << v.f2 << " " << v.f3;
}
};
}
int main() {
Dataset x(2);
// The http://www.gnuplot.info/demo/timedat.html example uses a tab between
// date and time, but this doesn't seem to work (gnuplot interprets it as
// two columns). So I use a comma.
x[0].datestr = "01/02/2003,12:34";
x[0].f1 = 1;
x[0].f2 = 2;
x[0].f3 = 3;
x[1].datestr = "02/04/2003,07:11";
x[1].f1 = 10;
x[1].f2 = 20;
x[1].f3 = 30;
Gnuplot gp;
gp << "set timefmt \"%d/%m/%y,%H:%M\"\n";
gp << "set xdata time\n";
gp << "plot '-' using 1:2 with lines\n";
gp.send1d(x);
return 0;
}
A similar thing can be done to support sending the data in a binary format. See example-data-1d.cc from the git repo for an example.
Alternatively, custom datatypes like this can be supported by overriding operator<<(std::ostream &, ...).
Another option is to use std::tuple (available in C++11) or boost::tuple instead of defining your own struct. These are supported out of the box (well, now they are, they weren't at the time that you asked the question).