OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
main.cpp
1
23
24#include "Plot/GoogleChart.hpp"
25#include "VCluster/VCluster.hpp"
26
28
29int main(int argc, char* argv[])
30{
46
47 openfpm_init(&argc,&argv);
48 auto & v_cl = create_vcluster();
49
50 // Google chart is only single processor
51 if (v_cl.getProcessingUnits() > 1)
52 {
53 std::cerr << "Error: only one processor is allowed" << "\n";
54 return 1;
55 }
56
58
71
75
77
125
126 // Fill the x values
127 x.add("one");
128 x.add("two");
129 x.add("three");
130 x.add("four");
131 x.add("five");
132 x.add("six");
133
134 // we have 4 dataset or lines
135 yn.add("dataset1");
136 yn.add("dataset2");
137 yn.add("dataset3");
138 yn.add("dataset4");
139
140 // Because we have 6 points on x each containing 4 lines or dataset, we have to provides
141 // 6 point with 4 values at each x point
142 y.add({2,3,5,6});
143 y.add({5,6,1,6});
144 y.add({2,1,6,9});
145 y.add({1,6,3,2});
146 y.add({3,3,0,6});
147 y.add({2,1,4,6});
148
150
168
169 GCoptions options;
170
171 options.title = std::string("Example");
172 options.yAxis = std::string("Y Axis");
173 options.xAxis = std::string("X Axis");
174 options.lineWidth = 5;
175
177
199
200 GoogleChart cg;
201 //
202 cg.addHTML("<h2>First graph</h2>");
203 cg.AddLinesGraph(x,y,yn,options);
204
206
207
234
235 options.stype = std::string("bars");
236
237 // it say that the dataset4 must me represented with a line
238 options.stypeext = std::string("{3: {type: 'line'}}");
239
240 cg.addHTML("<h2>Second graph</h2>");
241 cg.AddHistGraph(x,y,yn,options);
242
244
265
266 cg.addHTML("<h2>Third graph</h2>");
267
268 // The first colum are the values of a line while the other 2 values
269 // are the min and max of an interval, as we can see interval does not
270 // have to encapsulate any curve
271 y.clear();
272 y.add({0.10,0.20,0.19});
273 y.add({0.11,0.21,0.18});
274 y.add({0.12,0.22,0.21});
275 y.add({0.15,0.25,0.20});
276 y.add({0.09,0.29,0.25});
277 y.add({0.08,0.28,0.27});
278
279 // Here we mark that the the colum 2 and 3 are intervals
280 yn.clear();
281 yn.add("line1");
282 yn.add("interval");
283 yn.add("interval");
284
285 cg.AddLinesGraph(x,y,yn,options);
286
288
306
307 cg.addHTML("<h2>Four graph</h2>");
308
309 // again 6 point but 9 values
310 y.clear();
311 y.add({0.10,0.20,0.19,0.22,0.195,0.215,0.35,0.34,0.36});
312 y.add({0.11,0.21,0.18,0.22,0.19,0.215,0.36,0.35,0.37});
313 y.add({0.12,0.22,0.21,0.23,0.215,0.225,0.35,0.34,0.36});
314 y.add({0.15,0.25,0.20,0.26,0.22,0.255,0.36,0.35,0.37});
315 y.add({0.09,0.29,0.25,0.30,0.26,0.295,0.35,0.34,0.36});
316 y.add({0.08,0.28,0.27,0.29,0.275,0.285,0.36,0.35,0.37});
317
318 // colum 0 and 1 are lines
319 // colums 2-3 and 4-5 are intervals
320 // colum 6 is a line
321 // colum 7-8 is an interval
322 yn.add("line1");
323 yn.add("line2");
324 yn.add("interval");
325 yn.add("interval");
326 yn.add("interval");
327 yn.add("interval");
328 yn.add("line3");
329 yn.add("interval");
330 yn.add("interval");
331
332 // Intervals are enumerated with iX, for example in this case with 3 intervals we have i0,i1,i2
333 // with this line we control the style of the intervals. In particular we change from the default
334 // values
335 options.intervalext = std::string("{'i2': { 'color': '#4374E0', 'style':'bars', 'lineWidth':4, 'fillOpacity':1 } }");
336
337 cg.AddLinesGraph(x,y,yn,options);
338
340
367
369
370 xn.add(1.0);
371 xn.add(2.0);
372 xn.add(3.0);
373 xn.add(4.0);
374 xn.add(5.0);
375 xn.add(6.0);
376
377 options.intervalext = "";
378 options.width = 1280;
379 options.heigh = 720;
380 options.curveType = "line";
381 options.more = GC_ZOOM + "," + GC_X_LOG + "," + GC_Y_LOG;
382
383 cg.AddLinesGraph(xn,y,yn,options);
384
385 cg.write("gc_out.html");
386
388
389
403
404 openfpm_finalize();
405
406
408}
409
411
Small class to produce graph with Google chart in HTML.
void write(std::string file)
It write the graphs on file in html format using Google charts.
void AddLinesGraph(openfpm::vector< X > &x, openfpm::vector< Y > &y, const GCoptions &opt)
Add a simple lines graph.
void AddHistGraph(openfpm::vector< Y > &y)
Add an histogram graph.
void addHTML(const std::string &html)
Add HTML text.
Implementation of 1-D std::vector like structure.
Google chart options.
std::string stypeext
std::string intervalext
size_t width
width of the graph in pixels
size_t heigh
height of the graph in pixels
std::string xAxis
X axis name.
size_t lineWidth
Width of the line.
std::string more
more
std::string curveType
curve type
std::string title
Title of the chart.
std::string stype
std::string yAxis
Y axis name.