OpenFPM_pdata  1.1.0
Project that contain the implementation of distributed structures
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Pages
GoogleChart Class Reference

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

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

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");
options.barWD = true;
// 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_sc.html");

Create Lines

g_graph_plot2.jpg

This code produce the graph above

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

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 187 of file GoogleChart.hpp.

#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 AddLines (openfpm::vector< X > &x, openfpm::vector< Y > &y, const GCoptions &opt)
 Add lines 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_view_bar_option (const GCoptions &opt, size_t n_col)
 Construct a view option. 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 addView (std::ofstream &of, size_t i, std::string view)
 Add a view data variable. More...
 
void addDrawDiv (std::ofstream &of, size_t i, bool draw_view)
 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
 set of graphs
 
openfpm::vector< std::string > injectHTML
 set inject HTML;
 

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 335 of file GoogleChart.hpp.

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

Add a div section.

Parameters
offile ofstream
iid of the graph
gcGoogleChart option

Definition at line 410 of file GoogleChart.hpp.

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

Add a draw div section.

Parameters
offile out
iid
draw_viewdraw a chart(true) or view(false)

Definition at line 382 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 435 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 451 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 473 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 492 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 643 of file GoogleChart.hpp.

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

Add lines graph.

Parameters
yA vector of vectors of values. each vector is a graph of points
xGive a name or number to each x value, so can be a string or a number
optGraph options

Definition at line 525 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 value of the same point, for example error bar
xGive a name or number to each x value, so can be a string or a number
optGraph options

Definition at line 580 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 609 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 349 of file GoogleChart.hpp.

void GoogleChart::addView ( std::ofstream &  of,
size_t  i,
std::string  view 
)
inlineprivate

Add a view data variable.

Parameters
offile out
iid
viewstring

Definition at line 365 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.

Template Parameters
Xtype for the X coordinates
Ytype for the Y coordinates
Parameters
xvector of points on x
yvector of points on y
ynvector containing the name of each graph
optoptions to draw the graph
iindex of the graph we are drawing
Returns
string with the data section

Definition at line 209 of file GoogleChart.hpp.

std::string GoogleChart::get_view_bar_option ( const GCoptions opt,
size_t  n_col 
)
inlineprivate

Construct a view option.

Parameters
optGoogleChart option
Returns
the string

Definition at line 268 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 653 of file GoogleChart.hpp.


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