OpenFPM_io  0.2.0
Project that contain the implementation and interfaces for basic structure like vectors, grids, graph ... .
 All Data Structures Functions Variables Typedefs
GoogleChart Class Reference

Small class to produce graph with Google chart in HTML. More...

#include <GoogleChart.hpp>

Public Member Functions

template<typename Y >
void AddHistGraph (openfpm::vector< Y > &y)
 Add an histogram graph. More...
 
template<typename X , typename Y >
void AddHistGraph (openfpm::vector< X > &x, openfpm::vector< Y > &y)
 Add an histogram graph. More...
 
template<typename X , typename Y , typename Yn >
void AddHistGraph (openfpm::vector< X > &x, openfpm::vector< Y > &y, openfpm::vector< Yn > &yn)
 Add an histogram graph. More...
 
template<typename X , typename Y , typename Yn >
void AddHistGraph (openfpm::vector< X > &x, openfpm::vector< Y > &y, openfpm::vector< Yn > &yn, const GCoptions &opt)
 Add an histogram graph. More...
 
template<typename X , typename Y >
void AddLinesGraph (openfpm::vector< X > &x, openfpm::vector< Y > &y, const GCoptions &opt)
 Add a simple lines graph. More...
 
template<typename X , typename Y >
void AddLinesGraph (openfpm::vector< X > &x, openfpm::vector< Y > &y, const openfpm::vector< std::string > &yn, const GCoptions &opt)
 Add a simple plot graph. More...
 
void addHTML (const std::string &html)
 Add HTML text. More...
 
void write (std::string file)
 It write the graphs on file in html format using Google charts. More...
 

Private Member Functions

template<typename X , typename Y >
std::string get_points_plot_data (const openfpm::vector< X > &x, const openfpm::vector< Y > &y, const openfpm::vector< std::string > &yn, const GCoptions &opt, size_t i)
 Given X and Y vector return the string representing the data section of the Google Chart. More...
 
std::string get_colums_bar_option (const GCoptions &opt)
 
std::string get_points_plot_option (const GCoptions &opt)
 
void addData (std::ofstream &of, size_t i, const std::string &data)
 Add a graph data variable. More...
 
void addOption (std::ofstream &of, size_t i, const std::string &opt)
 Add an option data variable. More...
 
void addDrawDiv (std::ofstream &of, size_t i)
 Add a draw div section. More...
 
void addDiv (std::ofstream &of, size_t i, const GCoptions &gc)
 Add a div section. More...
 

Private Attributes

openfpm::vector< GGraphset_of_graphs
 
openfpm::vector< std::string > injectHTML
 

Detailed Description

Small class to produce graph with Google chart in HTML.

This Class can produce several graph using google chart

Create Histogram graph

g_graph_hist.jpg

This code produce the graph above

openfpm::vector<std::string> x;
openfpm::vector<openfpm::vector<size_t>> y;
openfpm::vector<std::string> yn;
x.add("colum1");
x.add("colum2");
x.add("colum3");
x.add("colum4");
x.add("colum5");
x.add("colum6");
// Each colum can have multiple data set (in this case 4 dataset)
// Each dataset can have a name
yn.add("dataset1");
yn.add("dataset2");
yn.add("dataset3");
yn.add("dataset4");
// Each colums can have multiple data-set
y.add({2,3,5,6});
y.add({5,6,1,6});
y.add({2,1,6,9});
y.add({1,6,3,2});
y.add({3,3,0,6});
y.add({2,1,4,6});
// Google charts options
GCoptions options;
options.title = std::string("Example");
options.yAxis = std::string("Y Axis");
options.xAxis = std::string("X Axis");
options.stype = std::string("bars");
// it say that the colum4 must me represented with a line
options.stypeext = std::string("{3: {type: 'line'}}");
cg.AddHistGraph(x,y,yn,options);
cg.write("gc_out.html");

Create Lines

g_graph_plot2.jpg

This code produce the graph above

openfpm::vector<std::string> x;
openfpm::vector<openfpm::vector<double>> y;
x.add("colum1");
x.add("colum2");
x.add("colum3");
x.add("colum4");
x.add("colum5");
x.add("colum6");
// Each line can have multiple intervals or error bars
// The first number specify the bottom line
// The last three numbers specify the top line + error band (min, max)
// The middle 5 line specify the middle lines + one external error band + one internal error band
y.add({0.10,0.20,0.19,0.22,0.195,0.215,0.35,0.34,0.36});
y.add({0.11,0.21,0.18,0.22,0.19,0.215,0.36,0.35,0.37});
y.add({0.12,0.22,0.21,0.23,0.215,0.225,0.35,0.34,0.36});
y.add({0.15,0.25,0.20,0.26,0.22,0.255,0.36,0.35,0.37});
y.add({0.09,0.29,0.25,0.30,0.26,0.295,0.35,0.34,0.36});
y.add({0.08,0.28,0.27,0.29,0.275,0.285,0.36,0.35,0.37});
// Google charts options
GCoptions options;
options.title = std::string("Example");
options.yAxis = std::string("Y Axis");
options.xAxis = std::string("X Axis");
options.lineWidth = 1.0;
cg.AddLinesGraph(x,y,options);
cg.write("gc_plot2_out.html");

Create lines with different styles

g_graph_plot.jpg

This code produce the graph above

openfpm::vector<std::string> x;
openfpm::vector<openfpm::vector<double>> y;
openfpm::vector<std::string> yn;
x.add("colum1");
x.add("colum2");
x.add("colum3");
x.add("colum4");
x.add("colum5");
x.add("colum6");
// Here we specify how many lines we have
// first Line
yn.add("line1");
// second line + 2 intervals (Error bands)
yn.add("line2");
yn.add("interval");
yn.add("interval");
yn.add("interval");
yn.add("interval");
// third line + 1 interval (Error bands)
yn.add("line3");
yn.add("interval");
yn.add("interval");
// Each line can have multiple intervals or error bars
// The first number specify the bottom line
// The last three numbers specify the top line + error band (min, max)
// The middle 5 line specify the middle lines + one external error band + one internal error band
y.add({0.10,0.20,0.19,0.22,0.195,0.215,0.35,0.34,0.36});
y.add({0.11,0.21,0.18,0.22,0.19,0.215,0.36,0.35,0.37});
y.add({0.12,0.22,0.21,0.23,0.215,0.225,0.35,0.34,0.36});
y.add({0.15,0.25,0.20,0.26,0.22,0.255,0.36,0.35,0.37});
y.add({0.09,0.29,0.25,0.30,0.26,0.295,0.35,0.34,0.36});
y.add({0.08,0.28,0.27,0.29,0.275,0.285,0.36,0.35,0.37});
// Google charts options
GCoptions options;
options.title = std::string("Example");
options.yAxis = std::string("Y Axis");
options.xAxis = std::string("X Axis");
options.lineWidth = 1.0;
options.intervalext = std::string("{'i2': { 'color': '#4374E0', 'style':'bars', 'lineWidth':4, 'fillOpacity':1 } }");
cg.AddLinesGraph(x,y,yn,options);
cg.write("gc_plot_out.html");

Definition at line 146 of file GoogleChart.hpp.

Member Function Documentation

void GoogleChart::addData ( std::ofstream &  of,
size_t  i,
const std::string &  data 
)
inlineprivate

Add a graph data variable.

Parameters
offile out
iid
datastring

Definition at line 258 of file GoogleChart.hpp.

void GoogleChart::addDiv ( std::ofstream &  of,
size_t  i,
const GCoptions gc 
)
inlineprivate

Add a div section.

Parameters
iid
gcGoogleChart option

Definition at line 304 of file GoogleChart.hpp.

void GoogleChart::addDrawDiv ( std::ofstream &  of,
size_t  i 
)
inlineprivate

Add a draw div section.

Parameters
offile out
iid

Definition at line 287 of file GoogleChart.hpp.

template<typename Y >
void GoogleChart::AddHistGraph ( openfpm::vector< Y > &  y)
inline

Add an histogram graph.

Parameters
yA vector of vectors the size of y indicate how many values we have on x each x value can have multiple values or datasets

Definition at line 328 of file GoogleChart.hpp.

template<typename X , typename Y >
void GoogleChart::AddHistGraph ( openfpm::vector< X > &  x,
openfpm::vector< Y > &  y 
)
inline

Add an histogram graph.

Parameters
yA vector of vectors the size of y indicate how many values we have on x each x value can have multiple values or datasets
xGive a name or number to each colums. Can be a string or a number

Definition at line 344 of file GoogleChart.hpp.

template<typename X , typename Y , typename Yn >
void GoogleChart::AddHistGraph ( openfpm::vector< X > &  x,
openfpm::vector< Y > &  y,
openfpm::vector< Yn > &  yn 
)
inline

Add an histogram graph.

Parameters
yA vector of vectors the size of y indicate how many values we have on x each x value can have multiple values or datasets
xGive a name or number to each colums. Can be a string or a number
ynGive a name to each dataset

Definition at line 366 of file GoogleChart.hpp.

template<typename X , typename Y , typename Yn >
void GoogleChart::AddHistGraph ( openfpm::vector< X > &  x,
openfpm::vector< Y > &  y,
openfpm::vector< Yn > &  yn,
const GCoptions opt 
)
inline

Add an histogram graph.

Parameters
yA vector of vectors the size of y indicate how many values we have on x each x value can have multiple values or datasets
xGive a name or number to each colums. Can be a string or a number
ynGive a name to each dataset
optGraph options

Definition at line 385 of file GoogleChart.hpp.

void GoogleChart::addHTML ( const std::string &  html)
inline

Add HTML text.

Parameters
htmladd html text in the page

Definition at line 482 of file GoogleChart.hpp.

template<typename X , typename Y >
void GoogleChart::AddLinesGraph ( openfpm::vector< X > &  x,
openfpm::vector< Y > &  y,
const GCoptions opt 
)
inline

Add a simple lines graph.

Parameters
yA vector of vectors of values. The size of y indicate how many x values we have, while the internal vector can store multiple realizations, or min and max, for error bar
xGive a name or number to each x value, so can be a string or a number
optGraph options

Definition at line 419 of file GoogleChart.hpp.

template<typename X , typename Y >
void GoogleChart::AddLinesGraph ( openfpm::vector< X > &  x,
openfpm::vector< Y > &  y,
const openfpm::vector< std::string > &  yn,
const GCoptions opt 
)
inline

Add a simple plot graph.

Parameters
yA vector of vector of values (numbers) the size of y indicate how many x values or colums we have, while the internal vector store multiple lines, or error bars
xGive a name or number to each colums, so can be a string or a number
ynGive a name to each line, or specify an error bar
optGraph options

Definition at line 448 of file GoogleChart.hpp.

void GoogleChart::addOption ( std::ofstream &  of,
size_t  i,
const std::string &  opt 
)
inlineprivate

Add an option data variable.

Parameters
offile out
iid
optstring

Definition at line 272 of file GoogleChart.hpp.

template<typename X , typename Y >
std::string GoogleChart::get_points_plot_data ( const openfpm::vector< X > &  x,
const openfpm::vector< Y > &  y,
const openfpm::vector< std::string > &  yn,
const GCoptions opt,
size_t  i 
)
inlineprivate

Given X and Y vector return the string representing the data section of the Google Chart.

Parameters
Xvector
Yvector
icounter
Returns
string with the data section

Definition at line 163 of file GoogleChart.hpp.

void GoogleChart::write ( std::string  file)
inline

It write the graphs on file in html format using Google charts.

Parameters
fileoutput file

Definition at line 492 of file GoogleChart.hpp.


The documentation for this class was generated from the following file: